i need populate 2d array odd numbers.
i want this
13579 13579 13579 13579
this have far:
public static void twodarray(){ //http://stackoverflow.com/questions/11243774/how-to-automatically-populate-a-2d-array-with-numbers int twodimention[][] = new int[5][3]; for(int i=0; i<twodimention.length; i++){ for(int j=0; j<twodimention[i].length; j++){ twodimention[i][j] = 2*i + 1; system.out.printf("%d5", twodimention[i][j]); } system.out.println(); }
it prints:
1515151515 3535353535 5555555555 7575757575 9595959595
can make work?
twodimention[i][j] = 2*j + 1; // j instead of system.out.print(twodimention[i][j]);
Comments
Post a Comment