关于java input.next()的问题
publicvoidsetupNewPlayer(){Scannerinput=newScanner(System.in);System.out.println("Ple...
public void setupNewPlayer()
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter the name of player1:");
player1.setName(input.next());
System.out.println("Now please enter the name of player2:");
player2.setName(input.next());
System.out.println("Ok, Player1 is " + player1.getName());
System.out.println("Player2 is " + player2.getName());
player1.setPosition(0);
player2.setPosition(0);
}
当我输入“ 2222 2222”的时候,后面的2222会直接赋给player2.getName(),请问要怎么解决呢? 展开
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter the name of player1:");
player1.setName(input.next());
System.out.println("Now please enter the name of player2:");
player2.setName(input.next());
System.out.println("Ok, Player1 is " + player1.getName());
System.out.println("Player2 is " + player2.getName());
player1.setPosition(0);
player2.setPosition(0);
}
当我输入“ 2222 2222”的时候,后面的2222会直接赋给player2.getName(),请问要怎么解决呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询