无法实现字符串输出


System.out.println("Write how many ml of water the coffee machine has: ");
int waterInMachine = scanner.nextInt();
System.out.println("Write how many ml of milk the coffee machine has: ");
int milkInMachine = scanner.nextInt();
System.out.println("Write how many grams of coffee beans the coffee machine has: ");
int beansInMachine = scanner.nextInt();
System.out.println("Write how many cups of coffee you will need: ");
int countCups = scanner.nextInt();
int water = 200 * countCups;
int milk = 50 * countCups;
int coffeeBeans = 15 * countCups;
int amountWater = waterInMachine;
int amountMilk = milkInMachine;
int amountCoffeeBeans = beansInMachine;
int count = 0;
while (amountWater > 200 && amountMilk > 50 && amountCoffeeBeans > 15) {
amountWater -= 200;
amountMilk -= 50;
amountCoffeeBeans -= 15;
count++;
}
if (waterInMachine >= water && milkInMachine >= milk && beansInMachine >= coffeeBeans && count > countCups) {
System.out.println("Yes, I can make that amount of coffee (and even " + (count - countCups) + " more than that)");
} else if (waterInMachine >= water && milkInMachine >= milk && beansInMachine >= coffeeBeans) {
System.out.println("Yes, I can make that amount of coffee");
} else if (count < countCups) {
System.out.println("No, I can make only " + count + " cup(s) of coffee");
}

条件无法正确显示字符串

如果咖啡机有足够的供应来制作指定量的咖啡,则程序应打印";是的,我可以煮那么多的咖啡;。如果咖啡机能做出更多的咖啡,程序应该输出";是的,我可以做那么多的咖啡(甚至N还多(";,其中N是咖啡机可以制作的额外咖啡杯数。如果资源量不足以制作指定量的咖啡;不,我只能泡N杯咖啡;。

与前一阶段一样咖啡机需要200毫升水,50毫升牛奶和15克咖啡豆制成一杯咖啡。

按条件输出时,除行外,所有内容都是正确的

if (waterInMachine> = water && milkInMachine> = milk && beansInMachine> = coffeeBeans && count> countCups) {
System.out.println ("Yes, I can make that amount of coffee (and even" + (count) + "more than that)"); 
}

如果我输入600 153 100 1,那么它将是是的,我可以煮那么多的咖啡(甚至比这个多1杯(但这是正确的是,我可以做那么多咖啡(甚至多2杯(TR

您在制作while咖啡时,您的配料已经足够了
这意味着当你有完全正确的配料时,你就不会煮咖啡了。

尝试更改:

while (amountWater > 200 && amountMilk > 50 && amountCoffeeBeans > 15)

对此:

while (amountWater >= 200 && amountMilk >= 50 && amountCoffeeBeans >= 15)

最新更新