Answer to Question #10495 in Java | JSP | JSF for Mike

Question #10495
Hello! How to initialize a two-dimensional array with particular values? Thanks!
1
Expert's answer
2012-06-07T07:39:05-0400
public class q10495 {
public static void main(String args[]) {

int[][] numbers = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 }

};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 4;
j++)
System.out.println("The element at [" + i + "][" + j + "]
is
" + numbers[i][j]);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS