0
package assign;
import java.util.Scanner;
public class File {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("How many chef do we have?");
int x = s.nextInt();
String [] names = new String[x];
if(x <= 0) {
do {
System.out.println("Please enter a valid number:");
x = s.nextInt();
}while (x <= 0);
}
for (int m = 0; m <= x-1; m++) {
System.out.println("Enter the name of " + m + ":");
String f = s.nextLine();
names [m] = f;
}
}
}
私の目的は、ユーザーの希望に応じてユーザーの名前を取得することです。しかし、このコードから、私の出力は次のようなものです:複数の入力を入力して保存する
How many chef do we have?
3
Enter the name of 0:
Enter the name of 1:
John
Enter the name of 2:
Jack
私は質問が注文に来int f = s.nextInt();
にString f = s.nextLine();
ラインを変更し、私は数字を書くことができる午前とき。
How many chef do we have?
3
Enter the name of 0:
Bob
Enter the name of 1:
John
Enter the name of 2:
Jack