System.out.println("Enter number of rows");
int row = sc.nextInt();
int[][] twod = new int[row][];
for (int i=0; i < row; i++)
{
int p = i+1;
System.out.println("Enter number of columns for row number "+p);
int column = sc.nextInt();
twod[row][column] = new int[row][column];
for(int k = 0; k < column;k++)
{
int wat = k+1;
System.out.println("Enter element in row number "+p+" and column number "+ wat);
twod[i][k] = sc.nextInt();
}
}
for(int men = 0; men < twod.length; men++)
{
for (int women = 0; women < twod[men].length; women++)
{
System.out.print(twod[men][women]);
}
}
當我嘗試運行程序,它給出INT [] []不能被轉換爲int
不兼容的類型:INT [] []不能被轉換爲int 數組twoD [行] [column] = new int [row] [column];
但我已經宣佈twod
爲int[][]
。那爲什麼會出現錯誤?
行''''''''[行] [列] =新int [行] [列];'做? – Jens