Double Dimension Arrays Java

My code works perfectly fine though i don't know how to print the number of the row before the word "row". It should be Row 1, Row 2, and so on. Any clues on how to do it? And also a clue to store these strings in a simpler way. Thank youuu :)

System.out.println("\t A \t B \t C \t D \t E \t F");
String [][] TwoDim = new String[13][6];
TwoDim[0][0] = "*";
TwoDim[0][1] = "*";
TwoDim[0][2] = "X";
TwoDim[0][3] = "*";
TwoDim[0][4] = "X";
TwoDim[0][5] = "X";

TwoDim[1][0] = "*";
TwoDim[1][1] = "X";
TwoDim[1][2] = "*";
TwoDim[1][3] = "X";
TwoDim[1][4] = "*";
TwoDim[1][5] = "X";

TwoDim[2][0] = "*";
TwoDim[2][1] = "*";
TwoDim[2][2] = "X";
TwoDim[2][3] = "X";
TwoDim[2][4] = "*";
TwoDim[2][5] = "X";

TwoDim[3][0] = "X";
TwoDim[3][1] = "*";
TwoDim[3][2] = "X";
TwoDim[3][3] = "*";
TwoDim[3][4] = "X";
TwoDim[3][5] = "X";

TwoDim[4][0] = "*";
TwoDim[4][1] = "X";
TwoDim[4][2] = "*";
TwoDim[4][3] = "X";
TwoDim[4][4] = "*";
TwoDim[4][5] = "*";

TwoDim[5][0] = "*";
TwoDim[5][1] = "X";
TwoDim[5][2] = "*";
TwoDim[5][3] = "*";
TwoDim[5][4] = "*";
TwoDim[5][5] = "X";

TwoDim[6][0] = "X";
TwoDim[6][1] = "*";
TwoDim[6][2] = "*";
TwoDim[6][3] = "*";
TwoDim[6][4] = "X";
TwoDim[6][5] = "X";

TwoDim[7][0] = "*";
TwoDim[7][1] = "X";
TwoDim[7][2] = "*";
TwoDim[7][3] = "X";
TwoDim[7][4] = "X";
TwoDim[7][5] = "*";

TwoDim[8][0] = "X";
TwoDim[8][1] = "*";
TwoDim[8][2] = "X";
TwoDim[8][3] = "X";
TwoDim[8][4] = "*";
TwoDim[8][5] = "X";

TwoDim[9][0] = "*";
TwoDim[9][1] = "X";
TwoDim[9][2] = "*";
TwoDim[9][3] = "X";
TwoDim[9][4] = "X";
TwoDim[9][5] = "X";

TwoDim[10][0] = "*";
TwoDim[10][1] = "*";
TwoDim[10][2] = "X";
TwoDim[10][3] = "*";
TwoDim[10][4] = "X";
TwoDim[10][5] = "*";

TwoDim[11][0] = "*";
TwoDim[11][1] = "*";
TwoDim[11][2] = "X";
TwoDim[11][3] = "X";
TwoDim[11][4] = "*";
TwoDim[11][5] = "X";

TwoDim[12][0] = "*";
TwoDim[12][1] = "*";
TwoDim[12][2] = "*";
TwoDim[12][3] = "*";
TwoDim[12][4] = "X";
TwoDim[12][5] = "*";

for(int i = 0; i<13; i++){
    System.out.print("Row \t");
    for(int j = 0; j <6; j++){
        System.out.print(TwoDim[i][j] + "\t");
    }
    System.out.println();
}

Answers


Change your line

System.out.print("Row \t");

to something like this:

System.out.print("Row " + (i + 1) + "\t");

Well, iis your row number, starting from 0, so just write (assuming you want to start at 1):

for(int i = 0; i<13; i++){
    System.out.print("Row \t"+(i+1)+" ");
    for(int j = 0; j <6; j++){
        System.out.print(TwoDim[i][j] + "\t");
    }
    System.out.println();
}

System.out.print("Row " + i +  "\t");

i is the first index in your array, and thus corresponds to the row. If you want to make is 1 based rather than a 0 based index, output i + 1 each time.


Don't use the hardcoded value of row and column,Use below code:

    for(int i = 0; i<TwoDim.length; i++){   // Iterate to row count

        System.out.print("Row-"+(i+1)+"\t"); // Change i to i+1

            for(int j = 0; j <TwoDim[i].length; j++){  // Iterate the column count
                System.out.print(TwoDim[i][j] + "\t");
        }

        System.out.println();
    }

Try this:

System.out.print("Row \t"+i);

In case your indexing starts from 1

 System.out.print("Row \t"+(i+1));

Did you tried:

for(int i = 0; i<13; i++){
   System.out.print("Row \t " + i);
   for(int j =0; j < 6; j++ {
       ...
   }
}

Need Your Help

i need the document.write code for iframe

javascript iframe document.write

I want the document.write code to load a page(as iframe)

Julia select element from tuple for each row in array

arrays indexing tuples julia

I know there has to be a clever way to do this in Julia but I'm stumped. I have a 1d array of tuples and I want to extract the third element from each row of the array. Here is an example of what I'm