ok so I need to use a 2d array to draw a hangman picture for a hangman game. the picture should be something like this
============
|<space>|
|<space>O
|<space>/|\
|<space>/\
|
|
but when i run this code with main. i get this

=
=
=
=
=
=
||
null
null
|
null
null
||
null
null
O
null
null
||
null
/
|
null
null
||
null
null
null
null
null
||
null
null
null
null
null

private void drawHangman(){

    int rows = 6;
    int cols = 6;
    String[][] draw = new String[rows][cols];

    for(int n=1; n<rows; n++){//draw hang pole ||
        draw[n][0] = "||";
    }

    for(int r=0; r<cols; r++){//draw hang pole =
        draw[0][r]= "=";
    }
    draw[1][3] = "|";

    if (wrong >= 1){//draw head
        draw[2][3] = "O";
    }
    if (wrong >= 2){//draw body
        draw[3][3] = "|";
    }
    if (wrong >= 3){//draw hand
        draw[3][2] = "/";
    }
    if (wrong >= 4){//draw hand
        draw[3][4] = "\\";
    }
    if (wrong >= 5){//draw leg
        draw[4][2] = "/";
    }
    if (wrong == 6){//draw leg
        draw[4][4] = "\\";
    }
    
    for(int x = 0; x < rows; x++){
        for(int y = 0;y < cols; y++){
            System.out.println(draw[x][y]);
        }
        
    }
    
}

System.out.println (short for Print Line) puts a newline char at the end whatever it prints, so you get one array element on each line.
System.out.print does the same as System.out.println but does not add the newline, so that's the one you need. You'll then need to do your own newline "\n" at the end of each row.
To get rid of the nulls, you need to ensure that every element contains a valid String (eg " ");

This article has been dead for over six months. Start a new discussion instead.