0

How to simplify Java array

Mynumber[][] b=new Mynumber[2][2]; b[0][0]=new Mynumber(); b[1][0]=new Mynumber(); b[0][1]=new Mynumber(); b[1][1]=new Mynumber(); b[0][0].n=50; b[0][1].n=60; b[1][0].n=70; b[1][1].n=80; Such as int[][] a={{10,20},{30,40}};

23rd Apr 2017, 5:47 AM
林峻霆
林峻霆 - avatar
2 odpowiedzi
+ 12
int num = 50; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { b[i][j] = new Mynumber(); b[i][j].n = num; num+=10; } } This should be purrrrfect.
23rd Apr 2017, 4:06 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Mynumer [][] b= {{new Mynumber (),new Mynumber ()}, {new Mynumber (),new Mynumber ()}}; should work
23rd Apr 2017, 8:14 AM
No One
No One - avatar