2

For our assignment. We have to create an Absolon game. But first we have to get the display board right. I programmed the display using a 2D array, 11 by 21. Using this code. And i got the following answer and it printed out correctly. (IDE Neatbeans)

    char [][] board = new char [11][21];

    for(int column =6; column <= 14; column=column+2 ) {
        int row = 0;
        board[row][column] = '=';
    }

    for(int column =6; column <= 14; column=column+2 ) {
        int row = 1;
        board[row][column] = 'o';
    }

    for(int column =6; column <= 14; column=column+2 ) {
        int row = 10;
        board[row][column] = '=';
    }

    for(int column =6; column <= 14; column=column+2 ) {
        int row = 9;
        board[row][column] = 'x';
    }

    for(int column =5; column <= 15; column=column+2 ) {
        int row = 2;
        board[row][column] = 'o';
    }

     for(int column =5; column <= 15; column=column+2 ) {
        int row = 8;
        board[row][column] = 'x';
    }

     for(int column =5; column <= 15; column=column+2 ) {
        int row = 8;
        board[row][column] = 'x';
    }

     for(int column =8; column <= 12; column=column+2 ) {
        int row = 3;
        board[row][column] = 'o';
    }

     for(int column =8; column <= 12; column=column+2 ) {
        int row = 7;
        board[row][column] = 'x';
    }

    int j=1;
     for(int column =4; column >= 0; column-- ) {
        board[j][column] = '"';
        j = j+1;
    }

     int l=1;
     for(int column =16; column <= 20; column++ ) {
        board[l][column] = '"';
        l = l+1;
    }

     int m=6;
     for(int column =1; column <= 4; column++ ) {
        board[m][column] = '"';
        m = m+1;
    }

     int n=6;
     for(int column =19; column >= 16; column-- ) {
        board[n][column] = '"';
        n = n+1;
    }


    //Print Out Board
    for(int row =0; row < board.length; row++) {
       for(int column =0; column < board[row].length; column++) {
           System.out.print(board[row][column] + ""); 
       } 
       System.out.println();
    }

}

}

This Is The Link to my sample output. http://postimg.org/image/dx656twrf/

But when i went to campus working on the same problem also using neatbeans. It gave me a completely new output.

=====

"ooooo"

"oooooo"

"ooo"

""

""

""

"xxx"

"xxxxxx"

"xxxxx"

=====

Whats wrong. Is it the IDE or my code. please help.

Simeon Jaganyi
  • 43
  • 1
  • 1
  • 4

2 Answers2

1

You have not initialized the characters in board to anything so they default to zero which prints differently on various systems. Initialize board with blanks and it will work.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Ok that makes perfect since. I've look but with not much luck, about how i would go about initializing the characters in board with blanks. `board[row][column] = '' ; ` Doesn't seem to work. – Simeon Jaganyi Sep 14 '13 at 17:09
  • Just loop throw the rows / columns like the other initialization, or maybe use `Arrays.fill` for the inner loop. – greg-449 Sep 14 '13 at 17:34
1

The memory of your multi-dimensional char array is initialized with null characters and different systems/fonts may render it differently.

Why does \0 print different output in different system in java

Community
  • 1
  • 1
Drew MacInnis
  • 8,267
  • 1
  • 22
  • 18