Я бы посоветовал печатать сообщения на консоли, чтобы подтвердить пользователю, что вы хотите ввести. В противном случае будет отображаться пустое окно. Я также предлагаю вам определить логическую переменную, чтобы избежать while l oop, переключив ваше достаточно на .next, а не на .nextLine. Таким образом, вы переопределяете свое логическое значение как false, чтобы разбить while l oop, а также получить желаемый результат, чтобы контролировать вывод своей программы. Это скомпилировано со всеми записями 1:
package com.climatedev.test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("How many bottles?");
Scanner scan = new Scanner(System.in);
int bottles = scan.nextInt() * 750;
int cnt = 1;
int platesTotal;
int potsTotal;
int nrPlates = 0;
int nrPots = 0;
boolean run = true;
while(run){
System.out.println("How many plates?");
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) {
System.out.println("Would you like to end the program? (Enter End)");
String enough = scan.next();
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);
run = false;
System.out.println("Goodbye");
break;
}
}
}
}
cnt++;
}
}
}
Я также немного изменил ваши бутылки, чтобы использовать nextInt, хотя это зависит от вашего использования. Если вы думаете, что конечный пользователь может ввести что-то вроде «Количество бутылок ...», это будет лучше, но в противном случае почему бы не использовать более простой вызов nextInt?