java - confusion of array -
char[][] boardgame = new char[10][10]; // suppose create array object (char[] row : boardgame) { arrays.fill(row, 'a'); } // suppose fill row in array char '*' // , im using "enhanced" loops (int = 0; < boardgame.length; i++) { (int j = 0; j < boardgame[i].length; j++) { system.out.print("|" + boardgame[i][j] + "|"); } // in loop above isn't "i" , "j" been overwrite // numbers declare int = 0 , update if // status true i++ // how come print|*||*||*||*||*|....instead of |1||2||3|...? system.out.println(); }
in inner for
loop above, "i" , "j" have been overwritten numbers, declare int = 0
, update if status true
i++
.
how come prints |*||*||*||*||*|...
instead of |1||2||3|...
?
boardgame[i][j]
returns char
stored @ index j
in dimension í
, , since have filled entire array asterisks, printed. if want print numbers, replace boardgame[i][j]
j
i suggest read this documentation details on how arrays work.
java arrays multidimensional-array
No comments:
Post a Comment