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}};
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.
+ 1
Mynumer [][] b=
{{new Mynumber (),new Mynumber ()},
{new Mynumber (),new Mynumber ()}};
should work