int之后读取输入

时间:2019-06-01 15:16:26

标签: java java.util.scanner

此代码可以正常运行,并且可以完成预期的操作,但是,如果我删除了“扫描仪类后的住所”并在注释获得第三次输入后将其粘贴,程序将终止。我真的不明白发生了什么。

public class InputTest {
     public static void main(String [] args) {

        Scanner in = new Scanner(System.in);

        System.out.println("Where do you live??");
        String country = in.nextLine();

        //get first input


        System.out.print("Type your first name ");
        String name = in.nextLine();

        //get second input
        System.out.print("Type your age");
        int age = in.nextInt();

        //get Third input


        //Concat all the strings and Display it on the console log
        System.out.println("Hello, " + name + ". Next year you'll be " + (age+1) + "in this Country" + country);


     }
 }

0 个答案:

没有答案