エラーjava.util.InputMismatchExceptionの意味と、それが発生する理由について知りたいです。このプログラムは、犬の情報を取得して文字列として保存するDog.javaというファイルのドライバクラスです。このファイルは、情報を直接取得し、後で情報を出力するものです。
私が入れているデータは次のとおりです。
Disco Bandito
4
Sally Struthers
5
Moosen
87
これが私のコードです:
import java.util.Scanner;
public class Kennel {
public static void main(String[] args) {
String value1 = null;
int value2 = 0;
String value3 = null;
int value4 = 0;
String value5 = null;
int value6 = 0;
//takes the input from a text file
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()){
value1 = scanner.nextLine();
value2 = scanner.nextInt();
value3 = scanner.nextLine();
value4 = scanner.nextInt();
value5 = scanner.nextLine();
value6 = scanner.nextInt();
}
//the three "dogs" in a kennel
Dog Dog1 = new Dog();
Dog1.setName(value1);
Dog1.getName();
Dog1.setAge(value2);
Dog1.getAge();
Dog1.toString();
Dog Dog2 = new Dog();
Dog2.setName(value3);
Dog2.getName();
Dog2.setAge(value4);
Dog2.getAge();
Dog2.toString();
Dog Dog3 = new Dog();
Dog3.setName(value5);
Dog3.getName();
Dog3.setAge(value6);
Dog3.getAge();
Dog3.toString();
System.out.println(Dog1.toString());
System.out.println(Dog2.toString());
System.out.println(Dog3.toString());
}
}
ありがとう、ジェイク