I want to break my while loop so that when it has looped all through the isEaten should go back to false private boolea
Posted: Sat Nov 27, 2021 2:32 pm
I want to break my while loop so that when it has looped all through the isEaten should go back to false
private boolean eaten;
public void openCalendar(ChocolatePiece[] array) {
Scanner input = new Scanner(System.in);
int chocolateEaten = 0;
int window;
while( chocolateEaten < array.length) {
System.out.print("Choose window: ");
window = Integer.parseInt(input.nextLine());
if (window < 0 || window > 23) {
System.out.println("Window is out of range");
} if (!array[window].isEaten()) {
chocolateEaten++;
System.out.println(array[window]);
array[window].setEaten(true);
} else {
System.out.println("Chocolate piece is eaten");
}
}
private boolean eaten;
public void openCalendar(ChocolatePiece[] array) {
Scanner input = new Scanner(System.in);
int chocolateEaten = 0;
int window;
while( chocolateEaten < array.length) {
System.out.print("Choose window: ");
window = Integer.parseInt(input.nextLine());
if (window < 0 || window > 23) {
System.out.println("Window is out of range");
} if (!array[window].isEaten()) {
chocolateEaten++;
System.out.println(array[window]);
array[window].setEaten(true);
} else {
System.out.println("Chocolate piece is eaten");
}
}