for (int i = 1; i <= value; i++) {
System.out.print("Player " + i + ", Please Enter your name : ");
String PlayerName = input.nextLine();
System.out.print("Please enter a number between 0 and 9 : ");
int PlayerNumber = input.nextInt();
System.out.println(PlayerName + " : " + PlayerNumber);
}
输出:Player 1, Please Enter your name : Please enter a number between 0 and 9 :
如果我将input.nextLine
更改为input.next
,则会等待用户首次输入,但他/她将无法写出其全名。
我的问题:我可以更改什么,以便用户可以先输入他的全名,然后输入他的号码?
答案 0 :(得分:1)
在input.nextInt()
for (int i = 1; i <= value; i++) {
input.nextLine(); //add this to top
System.out.print("Player " + i + ", Please Enter your name : ");
String PlayerName = input.nextLine();
System.out.print("Please enter a number between 0 and 9 : ");
int PlayerNumber = input.nextInt();
System.out.println(PlayerName + " : " + PlayerNumber);
}