gpt4 book ai didi

java - 瓶啤酒

转载 作者:行者123 更新时间:2023-12-01 22:03:37 25 4
gpt4 key购买 nike

我尝试制作一个卡在墙上的啤酒瓶版本,这对很多人来说都是基本的。

这就是我所拥有的,但我不明白为什么我没有得到任何输出?

如有任何帮助,我们将不胜感激。谢谢

public class PeopleInARoom
{

public static void main(String[] args) {
int humanNum = 10;
String word = "people";

while (humanNum < 0) {

if (humanNum == 1) {
word = "person"; //singular, as in one person.
}

System.out.println(humanNum + " " + word + "people in a room");
System.out.println("Wait...somebody left!");
humanNum = humanNum - 1;

if (humanNum > 0) {
System.out.println(humanNum + " " + word + "people in a room");
} else {
System.out.println("Hey, where has everybody gone?");
}
}
}
}

最佳答案

你有:

int humanNum = 10;

你的条件是while(humanNum < 0) {...}condition永远不会满足,所以什么也不会发生。

关于java - 瓶啤酒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33239957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com