2015-06-26 121 views
-2
import java.io.*; 
public class redtry4 { 
    public static void main(String[]args)throws IOException{ 
     BufferedReader IN = new BufferedReader(new InputStreamReader(System.in)); 
     String[]numx = new String[10]; 
     System.out.println("Enter 10 different numbers:"); 
     for(int b=0; b<10; b++) 
     { 
      System.out.println("Accepted numbers are:"+"\n"+b); 
      numx[b]=Integer.parseInt(IN.readLine()); 

     } 
    } 
} 

I keep getting error: Incomptaible type on numx[b]=Integer.parseInt(IN.readLine());.的Java類型不兼容

+1

您還可以考慮使用'Scanner'從控制檯讀取輸入;) – MadProgrammer

回答

2

numx是字符串和Integer.parseInt(IN.readLine())返回類型是int,因此錯誤。

要麼改變你的NUM陣列是一個字符串數組

int[]numx = new int[10]; 

或不使用Integer.parseInt隱蔽價值爲整數。

numx[b]=IN.readLine(); 

選擇是你的,這取決於你的需要。

0

變化

String[]numx = new String[10]; 

int[]numx = new int[10]; 

如果要分析的輸入爲整數,它們存儲在一個int數組。 如果您仍然希望將它們存儲在字符串數組中,請勿調用parseInt