- 1

I am not able to get Multidimensional Array's this code ! I need help 🤔

// Manually allocate differing size second dimensions. class TwoDAgain { public static void main(String args[]) { int twoD[][] = new int[4][]; twoD[0] = new int[1]; twoD[1] = new int[2]; twoD[2] = new int[3]; twoD[3] = new int[4]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<i+1; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<i+1; j++) System.out.print(twoD[i][j] + " "); System.out.println();

28th Jan 2017, 1:19 PM
Puneet Thakur
Puneet Thakur - avatar
2 Antworten
0
int twoD[][] = new int[4][] This statement is incorrect as you need to mention the Number of column as well.
28th Jan 2017, 2:20 PM
Arpan Lunawat
Arpan Lunawat - avatar
0
this statement is valid ! :)
6th Jan 2018, 8:07 AM
Puneet Thakur
Puneet Thakur - avatar