Java使用Scanner读取多行输入跳出问题

源代码如下:

                Scanner in = new Scanner(System.in);
		
		System.out.println("Pls insert Title");
		ja.setJTitle(in.nextLine());
		System.out.println("Pls insert Number");
		ja.setJNumber(in.nextInt());
		System.out.println("Pls insert Pay");
		ja.setJPay(in.nextInt());
		System.out.println("Pls insert Description");
		ja.setJDes(in.nextLine());
		
		in.close();
		
		Job.displayInfo();

程序在读取JPay后运行println后自动跳过JDes读取,直接至dispalyInfo

运行结果如:


经过参考帖子:http://blog.csdn.net/xiao_niu_1/article/details/8240650 后修改代码为:

                Scanner in = new Scanner(System.in);
		
		System.out.println("Pls insert Title");
		ja.setJTitle(in.nextLine());
		System.out.println("Pls insert Number");
		ja.setJNumber(in.nextInt());
		System.out.println("Pls insert Pay");
		ja.setJPay(in.nextInt());
		in.nextLine();
		System.out.println("Pls insert Description");
		ja.setJDes(in.nextLine());
		
		in.close();
		
		Job.displayInfo();

在读取JPay后添加in.nextLine()

运行结果:


你可能感兴趣的:(我的Java进步史)