import java.util.Scanner;
public class Words
{
public static void main (String[] args)
{
Scanner myScan = new Scanner(System.in);
String s1;
int myAge;
int time = 6;
System.out.print("What is your name? ");
s1 = myScan.nextLine();
System.out.print("How old are you? ");
myAge = myScan.nextInt();
System.out.println("Really? Cause I am " + (myAge+3) + ". " + "Lets's meet up! ");
s1 = myScan.nextLine();
}
}
//在执行完最后一条命令后,它不会让我在终端窗口中键入任何内容。请帮忙。
最佳答案
在之间添加nextLine()
System.out.print("How old are you? ");
myAge = myScan.nextInt();
myScan.nextLine(); // add this
System.out.println("Really? Cause I am " + (myAge+3) + ". " + "Lets's meet up! ");
s1 = myScan.nextLine();
这是必需的,因为
nextInt()
仅消耗读取的int
值,而不消耗其后的任何行尾字符。nextLine()
将使用\r\n
(或任何行尾/分隔符),而下一个标记将可供其他nextLine()
使用。