看板 java 關於我們 聯絡資訊
我在寫一個可以把輸入的值存入陣列的程式 int[] a= new int[50] String str = new String(); for(int i=0;i<=50;i++){ str=br.readLine(); a[i]=Integer.parseInt(str); } 這樣寫不知道對不對? compile沒問題 但是在run的時候出現 Exception in thread "main" java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:470) at java.lang.Integer.parseInt(Integer.java:499) at Append.main(Append.java:12) 請問這是哪裡出了問題了呢?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 115.165.238.12
tkcn:看 Exception 第 1 行: "" <- 這是空字串 03/12 19:26
jack020408:是指我輸入了空字串嗎? 03/12 19:30
demisoda:i != 50 03/12 19:35
jack020408:改49了 好像還是一樣@@ 輸入第一個值可以 第二個值就 03/12 19:41
jack020408:錯了 03/12 19:43
PsMonkey:是不是該先瞭解 NumberFormatException 的意思.... 03/12 19:56
jack020408:謝謝 已解決... 03/12 20:12