System.out.println("输入年龄:");
int a=sc.nextInt();
System.out.println("姓名:");
String b=sc.nextLine();
System.out.println("性别:");
String c=sc.nextLine();
上面这样写会出错,年龄之后的无法输入
解决办法
用nextLine确实是有问题,直接结束了,你可以用next()替换nextLine()。
scanner有个扫描器,nextLine方法是返回当前行的其余部分,当前位置移至下一行的行首。
在前一个scan.nextInt()后,扫描器停在了这个整数后面,你再调用一次nextLine(),返回的是这个整数后面到下一行首,所以是空的。