I want to break my while loop so that when it has looped all through the isEaten should go back to false private boolea

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

I want to break my while loop so that when it has looped all through the isEaten should go back to false private boolea

Post by answerhappygod »

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");
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply