2015-10-20 64 views
0

我曾嘗試在牆上製作一瓶啤酒,這是很多人的基本習慣。瓶啤酒

這是我的,但我不明白爲什麼我沒有得到任何輸出?

任何幫助,將不勝感激。由於

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?"); 
      } 
     } 
    } 
} 
+7

'int human = 10','while(humanNum <0)',只是一點提示;) – SomeJavaGuy

+0

humanNum被聲明爲10,但是while循環不會被應用,因爲它大於0。只會在humanNum小於0時執行。 – Sky

+0

while(humanNum> 0) – Sky

回答

3

您有:

int humanNum = 10; 

,你的條件是while(humanNum < 0) {...}condition永遠不會滿足,所以沒有任何反應。