0

I want to number the row and column . I get row number right around the left hand side ..I want the column number on the top..This is the code I have ..CAN PLLZZ HELP ME WID the column number plzz..

    int[][] Board = new int[15][15];
    for(int j=0;j<Board.length;j++)
     System.out.print(" "+j+"  ");
    for (int r = 0; r < Board.length; r++) {

        System.out.print("\n"+r);
        for (int c = 0; c < Board[r].length; c++) {

            System.out.print("__" + " ");

        }
        System.out.println();

    }

Edited by mike_2000_17: Fixed formatting

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by sanam_1
0

One easy way to do this is as below.

int[][] Board = new int[15][15];
 for (int j = 0; j < Board.length; j++) {
  System.out.print((j < 10) ? " " + j + "\t" : j + "\t");} //use tab (\t) to introduce space with constant width. 
 for (int r = 0; r < Board.length; r++) {
  if (r != 0) {
   System.out.print((r < 10) ? "\n " + r : "\n" + r);
   } else {continue;}
 for (int c = 0; c < Board[r].length - 1; c++) {
  System.out.print("\t__");}
  System.out.println();
}

Alternatively you could read about formatted printing.
Hope this helps.

0

Why there are 3 loops??? Also, the curry brackets are not correct either...

You should not post the code right way but rather tell them the algorithm or idea. Unless it is unclear, you could give some sample codes.

0

@kekkaishi
Sorry for the previous post. I didn't understand the output. Anyway, please do not just post the solution right away but rather explain it to the person.

0

@Kekkaishi
this works but 0 is showing only one time...da 0 should show for both row and column...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.