nextLine()方法说是遇到\r\n就结束嘛?
Scanner sc = new Scanner(System.in);
System.out.println("第一个字符串:");
String s1 = sc.nextLine();
System.out.println("第二个字符串:");
String s2 = sc.nextLine();
System.out.println("s1 = " + s1 + ", s2 = " + s2);
这个代码可以两个都能获取到而下面这段代码就不行了呢?
Scanner sc = new Scanner(System.in);
System.out.println("第一个数字:");
int s1 = sc.nextInt();
System.out.println("第二个字符串:");
String s2 = sc.nextLine();
System.out.println("s1 = " + s1 + ", s2 = " + s2);
这两段代码貌似第二个获取前都有一个\r\n啊?! |
|