0

I'm trying to figure out how to print a two-dimensional array by column. This is what I have so far:

public class Orwell2 {

public static void main(String[] args) {
    char[][] orwell = {
            {'I', 't', '*', 'w', 'a', 's', '*'},
            {'a', '*', 'b', 'r', 'i', 'g', 'h'},
            {'t', '*', 'c', 'o', 'l', 'd', '*'},
            {'d', 'a', 'y', '*', 'i', 'n', '*'},
            {'A', 'p', 'r', 'i', 'l', ',', '*'},
            {'a', 'n', 'd', '*', 't', 'h', 'e'},
    };

for (char a = 0; a < orwell.length; a++) {
    for (char b = 0; b < orwell[0].length; b++) {
        System.out.print(orwell[a][b] + " ");
    }
    System.out.println();
}
}

}

I need to print the array as

IatdAat apn bcyrdwro i aililtsgdn,h h e

Edit: Just so everyone knows, I have absolutely no idea what I'm doing.

  • 1
    Why are `a` and `b` declared as type `char`, when they are used as array indices? – kaya3 Dec 11 '19 at 01:10
  • for (int a = 0; a < orwell[0].length; a++) { for (int b = 0; b < orwell.length; b++) { System.out.print(orwell[b][a] + " "); } – Kum Dec 11 '19 at 01:17

0 Answers0