I want to arrange a random input string array to a table look use a loop and if functions or something easier.
There are smallest, small, medium, big, and biggest. And the string are duplicate x5 each
The array is:
String cow[][] = new String[5][5];
cow[0][0] = "big";
cow[0][1] = "smallest";
cow[0][2] = "small";
cow[0][3] = "medium";
cow[0][4] = "biggest";
cow[1][0] = "smallest";
cow[1][1] = "biggest";
cow[1][2] = "medium";
cow[1][3] = "small";
cow[1][4] = "big";
cow[2][0] = "medium";
cow[2][1] = "biggest";
cow[2][2] = "big";
cow[2][3] = "smallest";
cow[2][4] = "small";
cow[3][0] = "small";
cow[3][1] = "big";
cow[3][2] = "smallest";
cow[3][3] = "medium";
cow[3][4] = "biggest";
cow[4][0] = "biggest";
cow[4][1] = "medium";
cow[4][2] = "big";
cow[4][3] = "small";
cow[4][4] = "smallest";
My code for arrange the array:
for (int j = 0; j < cow.length; j++) {
for (int i = 0; i < cow[j].length; i++) {
if (cow[i][j] == "smallest") {
System.out.print("| " + cow[i][j] + " |");
} else if (cow[i][j] == "small") {
System.out.print("| " + cow[i][j] + " |");
} else if (cow[i][j] == "medium") {
System.out.print("| " + cow[i][j] + " |");
} else if (cow[i][j] == "big") {
System.out.print("| " + cow[i][j] + " |");
} else if (cow[i][j] == "biggest") {
System.out.print("| " + cow[i][j] + " |");
}
}
System.out.println();
}
When I run the code, I only get
smallest |
smallest |
smallest |
smallest |
smallest |
I think its because the loop didnt re-loop(?) for other index, so the table not 5x5
What I expected:
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
smallest | small | medium | big | biggest
please kindly teach me, because i very new to java. thanks