Java Can';t实现字符串输出
如果我输入600 153 100 1,那么它将是是的,我可以煮那么多咖啡(甚至比那多1杯)Java Can';t实现字符串输出,java,Java,如果我输入600 153 100 1,那么它将是是的,我可以煮那么多咖啡(甚至比那多1杯) 但是这个权利是的,我可以煮那么多的咖啡(甚至比那多两杯)你在煮咖啡,而你的配料太多了。 这意味着如果你的配料量正好合适,你就不会煮咖啡了 尝试更改此选项: while(amountWater>200&&amountMilk>50&&amountCoffeeBeans>15) 为此: while(amountWater>=200&&amountMilk>=50&&amountCoffeeBeans>=15
但是这个权利是的,我可以煮那么多的咖啡(甚至比那多两杯)你在煮咖啡
,而你的配料太多了。
这意味着如果你的配料量正好合适,你就不会煮咖啡了
尝试更改此选项:
while(amountWater>200&&amountMilk>50&&amountCoffeeBeans>15)
为此:
while(amountWater>=200&&amountMilk>=50&&amountCoffeeBeans>=15)
当您只需要200份水时,为什么需要201份水(其他两种成分也是如此)?你当时是怎么想的?在这段时间内检查一下你的情况——正如前面提到的,你可以用200毫升水、50毫升牛奶和15克咖啡来煮咖啡,所以“>”可能是个问题。
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");
}
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)");
}