[J2SE] 關於System.in的問題請教
OK 事情是這樣的
小的是Java新手,發神經在嘗試input String時, 有了下列疑問:
====== Code Part ======
Scanner sc = new Scanner(System.in);
String strInput = sc.nextLine();
如果輸入 12345\nabcde
輸出為 12345\nabcde
若改成
String s = "12345\nabcde";
Scanner sc1 = new Scanner(s);
System.out.println(sc1.nextLine());
System.out.println(sc1.nextLine());
輸出會變成:
12345
abcde
傻呼呼的將第一段改成
Scanner sc = new Scanner(System.in);
String strInput = sc.nextLine();
Scanner sc2 = new Scanner(strInput);
System.out.println(sc2.nextLine());
System.out.println(sc2.nextLine());
輸入12345\nabcde時,輸出同樣是12345\nabcde
印象中, newxLine() 與 next() 主要差異是遇到空白或挑脫字元(\n)時,
是否接續到讀取到敲enter的點
但System.in在收到input內容有\n時,卻無法如預期跳行
還請神人指點小的觀念上的誤判點
Orz... (先行跪拜)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.196.138
※ 文章網址: https://www.ptt.cc/bbs/java/M.1440121578.A.40C.html
→
08/21 10:51, , 1F
08/21 10:51, 1F
→
08/21 10:51, , 2F
08/21 10:51, 2F
→
08/21 11:02, , 3F
08/21 11:02, 3F
→
08/21 11:03, , 4F
08/21 11:03, 4F
→
08/21 11:25, , 5F
08/21 11:25, 5F
→
08/21 11:40, , 6F
08/21 11:40, 6F
→
08/21 11:41, , 7F
08/21 11:41, 7F
→
08/21 11:42, , 8F
08/21 11:42, 8F
→
08/21 11:43, , 9F
08/21 11:43, 9F
→
08/21 11:43, , 10F
08/21 11:43, 10F
→
08/21 11:44, , 11F
08/21 11:44, 11F
推
08/21 11:48, , 12F
08/21 11:48, 12F
→
08/21 12:04, , 13F
08/21 12:04, 13F
→
08/21 12:10, , 14F
08/21 12:10, 14F