0
私は、スキャナを使ってユーザ入力を私がすでに宣言している整数に変換する方法を知りました。私はすでにperson1というオブジェクトを作成し、 'Person'クラスのfirstName、lastName、age、genderという変数を宣言しています。私は解析を使用する必要がありますが、私は自分のコード内で実装する方法がわかりません。文字列を整数またはオブジェクトに変換する
Scanner user_input = new Scanner(System.in);
System.out.println("Please input your details.");
System.out.println("First Name:");
person1.setFirstName(user_input.nextLine());
System.out.println("Last Name:");
person1.lastName = user_input.nextLine();
System.out.println("Age:");
person1.age = user_input.nextLine();
System.out.println("Gender:");
person1.gender = user_input.nextLine();
9行目と11行目を変更する必要があります。
スニペットコードの行数をカウントしたくない... – Guillaume
。入力時に数値のみを入力していることを考慮して –