I made a 2D array containing integer values and want to convert it into a string, but I'm really confused on what I'm able to put into //something to get the output I want.
public static void main(String[] args) {
final int [][] test = { {1, 6, 11, 16, 21},
{2, 7, 12, 17, 22},
{3, 8, 13, 18, 23},
{4, 9, 14, 19, 24},
{5, 10, 15, 20, 25} };
System.out.println(TwoDOneD.DownNUp(test));
public static String DownNUp(int [][] test) {
String res = "";
for (int r = 0; r < test[0].length; r++) {
for (int c = 0; c < test.length; c++) {
if (c % 2 == 1) {
//something
} else {
res += test[c][r] + " ";
}
}
}
return res;
}
The output I'm trying to get is why I have (c % 2 == 1); in every odd column, it's supposed to go down, and in every even column, it goes right back up.
1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 20 19 18 17 16 21 22 23 24 25