mardi 10 avril 2018

How to compare chars in java?

Why is my comparison always false? what am i doing wrong? here is the code:

    char image[][] = {
            {'*','*',' ',' ',' ',' ',' ',' ','*',' '},
            {' ','*',' ',' ',' ',' ',' ',' ','*',' '},
            {' ',' ',' ',' ',' ',' ','*','*',' ',' '},
            {' ','*',' ',' ','*','*','*',' ',' ',' '},
            {' ','*','*',' ','*',' ','*',' ','*',' '},
            {' ','*','*',' ','*','*','*','*','*','*'},
            {' ',' ',' ',' ',' ',' ',' ',' ','*',' '},
            {' ',' ',' ',' ',' ',' ',' ',' ','*',' '},
            {' ',' ',' ','*','*','*',' ',' ','*',' '},
            {' ',' ',' ',' ',' ','*',' ',' ','*',' '}
    };

This is what the comparison looks like:

if(image[posY][posX+1] == '*')

(when posy = 0 and posx = 0) and yes ive printed it out just to be sure it was a star '*'

Aucun commentaire:

Enregistrer un commentaire