My question is that in my code i have a scanner that asks the user to input true or false to fill a grid made from an array. I want an error message to occur when the user types something other than the boolean allows. I know i have to another else if to my if statement then loop the program round but what is the word in java language for anything but true/false? Sorry if this is unclear i am unsure how to word the problem you may get a better idea in my code below.
boolean updown = sc.nextBoolean();
if (updown == true) {
grid[x+1][y] = 'S';
grid[x+2][y] = 'S';
grid[x+3][y] = 'S';
grid[x+4][y] = 'S';
drawGrid(grid);
}
else if (updown == false) {
grid[x][y+1] = 'S';
grid[x][y+2] = 'S';
grid[x][y+3] = 'S';
grid[x][y+4] = 'S';
drawGrid(grid);
}
else if (updown == ) (user needs to get error message here)
if (updown == true) {
grid[x+1][y] = 'S';
grid[x+2][y] = 'S';
grid[x+3][y] = 'S';
grid[x+4][y] = 'S';
drawGrid(grid);
}
else if (updown == false) {
grid[x][y+1] = 'S';
grid[x][y+2] = 'S';
grid[x][y+3] = 'S';
grid[x][y+4] = 'S';
drawGrid(grid);
Aucun commentaire:
Enregistrer un commentaire