public class Demo07 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//s2还没有输入,程序直接结束。
int s1 = sc.nextInt();
System.out.println(s1);
String s2 = sc.nextLine();
System.out.println(s2);
//方法一:将nextLine调用放在前面,nectInt放在后面
String s2 = sc.nextLine();
System.out.println(s2);
int s1 = sc.nextInt();
System.out.println(s1);
//方法二:调用两次nextLine
int s1 = sc.nextInt();
System.out.println(s1);
String s2 = sc.nextLine();
String s3 = sc.nextLine();
System.out.println(s3);
//方法三:全部使用nextInt()方法扫描,将结果转化为int类
int s1 = Integer.parseInt(sc.nextLine());
System.out.println(s1);
String s2 = sc.nextLine();
System.out.println(s2);
}
}
解决nextInt()调用完后,nextLine没有等控制台输入,遇到回车直接结束的三种方法
最新推荐文章于 2024-05-17 17:10:41 发布