看板 java 關於我們 聯絡資訊
import java.io. import java.util.*; public class test12 { public static void main(String[] args){ System.out.println("請輸入九個數字"); int[] x = new int[9]; Scanner sc = new Scanner(new BufferedInputStream(System.in)); while(sc.hasNext()) { for(int i=0;i<9;i++){ x[i]=sc.nextInt(); } } } } 我想把輸入的九個數字, 例如 1 2 3 4 5 6 7 8 9 丟到x陣列中 但是程式一跑之後,就沒反應了 不知道是什麼問題?? 有大大可以幫我解答嗎?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.243.182.13
slalala:先搞清楚sc.hasNext()的邏輯吧 04/20 00:19
ssc24:被while包住,所以程式不會停止, 04/20 11:17
risker760915:1.多出個不明用途的while 2.建議用try catch檢查輸入 04/20 14:17