2014-09-20 45 views
-2
public class Solution { 
public static void main(String[] args) throws IOException 
    { 
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
    int num = 6; 
    int[] sticks = new int[num]; 
    for(int i=0;i<num;i++) 
    { 
     sticks[i] = Integer.parseInt(br.readLine()); 
    } 
    for(int i=0;i<num;i++) 
    { 
     System.out.println(sticks[i]); 
    } 

    }} 

在線程 「主」 java.lang.NumberFormatException例外:對於輸入字符串: 「4 5 8 6 4 2」異常在線程 「主」 java.lang.NumberFormatException在輸入字符串

+0

在新行上輸入每個數字... – mmk 2014-09-20 17:36:22

+4

因爲'4 5 8 6 4 2'不是有效的數字。注意空格。 – 2014-09-20 17:36:44

回答

4

字符串"4 5 8 6 4 2"不能被解析爲數字。嘗試使用split,或在單獨的行上輸入每個號碼。

相關問題