dimanche 27 novembre 2016

Simplification of successive if statements in Java

I have a series of if statements as shown below:

if (board[x+1][y]==true) {
    ar+=1;
}
if (board[x][y+1]==true) {
    ar+=1;
}
if (board[x-1][y]==true) {
    ar+=1;
}
if (board[x][y-1]==true) {
    ar+=1;
}
if (board[x+1][y+1]==true) {
    ar+=1;
}
if (board[x+1][y-1]==true) {
    ar+=1;
}
if (board[x-1][y+1]==true) {
    ar+=1;
}
if (board[x-1][y-1]==true) {
    ar+=1;
}

Is there a way to simplify/condense these statements with Java?

Any suggestions appreciated.

Aucun commentaire:

Enregistrer un commentaire