JAVA如何在不知道數據量多少的情況下,以回車結束輸入


Scanner input = new Scanner(System.in);
System.out.print("請輸入數字:(最后回車結束!!)");
String line = input.nextLine();
Scanner input1 = new Scanner(line);
Node e = new Node();
while(input1.hasNext()){
e.add(e,input1.nextInt());
}
設置兩個Scanner 第一個以行為單位讀取數據,這樣就相當於是用回車(enter)當作結束符,
然后把讀取到的字符串傳入第二個Scanner, 然后在進行處理


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM