public class BeerSong {
public static void main(String[] args) {
int beerNum = 99;
String word = "bottles";
while (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + word + " of beer.");
System.out.println("Take one down.");
System.out.println("Pass it around.");
beerNum = beerNum - 1;
if (beerNum == 1) {
word = "bottle"; // singular, as in ONE bottle.
}
if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more bottles of beer on the wall");
} // end else
} // end while loop
} // end main method
} // end class
이 코드를 출력합니다 경우는 while 루프 내부에
99 bottles of beer on the wall
99 bottles of beer on the wall.
99 bottles of beer.
Take one down and pass it around.
왜 이렇게 인쇄되지 않습니다
99 bottles of beer on the wall
99 bottles of beer.
Take one down and pass it around, 99 bottles of beer on the wall.
은 if 문 루프 후이기 때문에
는 "이 코드는 출력한다 :"와 같은
최종 코드는 볼 수 없음은하지 않습니다. 'Take down down '과'Pass it around'를 각각''와''와 대문자와 구두점을 사용하지 않고 별도의 줄에 인쇄합니다. –
'if' 문은 루프 다음에 없습니다. 그것은 루프 안에 있습니다. – khelwood
코드에 어떤 문제가 있습니까? 앤디 터너 (Andy Turner)가 이미 지적했듯이 원하는대로 인쇄하지 않더라도 정확한 것으로 보입니다. 3 번째와 4 번째의 print 서술문 ('System.out.println ("Take down one.");'과'System.out.println ("전달");')을'System.out.print ("하나를 가지고 내려 주변을 지나쳐라.") 거의 끝내야한다. – Thomas