Im trying to stop a loop that takes integers after typing in the console "End", but i cant seem to find a way to do it.
Scanner scan = new Scanner(System.in);
int bottles = Integer.parseInt(scan.nextLine()) * 750;
int cnt = 1;
int platesTotal;
int potsTotal;
int nrPlates = 0;
int nrPots = 0;
while(true){
int plates = scan.nextInt();
platesTotal = plates * 5;
if(cnt%3==0) {
int pots = scan.nextInt();
nrPots = nrPots + pots;
nrPlates = nrPlates + pots;
potsTotal = pots * 15;
if (bottles < potsTotal + platesTotal) {
System.out.println("Not enough detergent, " + (potsTotal + platesTotal - bottles) + " ml. more necessary!");
break;
}
else
if(bottles >= potsTotal + platesTotal) {
String enough = scan.nextLine();
if (enough.equals("End")) {
if (bottles >= potsTotal + platesTotal) {
System.out.println("Detergent was enough!");
System.out.println(nrPlates + " dishes and " + nrPots + "pots were washed.");
System.out.printf("Leftover detergent %d ml.", bottles - potsTotal - platesTotal);
break;
}
}
}
}
cnt++;
}
after inputting the string ("End"), it needs to show me the total of dishes and pots, and how much detergent it has left, and if the required amount of detergent is more than the available amount, it needs to show me how much more is needed.