2014-11-12 1 views
0

유명한 노래 "벽에있는 XXX 병 99 개"를 자동화하려고합니다. 노래의 99 개 구절의 가사를 인쇄합니다. 루프를 사용하십시오! 당신이 가사를 모르는 경우에, google에 그 (것)들을 위로보십시오.내 코드를 실행할 때 내 번호가 표시되지 않는 이유

이 프로그램은해야한다 : 사용자가 21 세 이상인 경우

  • 은 맥주 또는 소다

    을 선호하는 경우 그들에게, 그들의 나이

  • 의 사용자에게 문의하십시오. 그들이 21 세 미만이거나 소다를 선호하는 경우 가사는 "벽에 소다 99 병"입니다.

    b. 21 세 이상인 경우 "99 병의 맥주"입니다.

  • 회 돌이를 사용해야하며 카운터 변수는 반드시 print 문에 포함되어야합니다!

  • 은 그래서 첫 번째 구절은 다음과 같습니다 소다의

    99 병 벽에 소다

    99 병

    그 병 중 하나가 벽을 넘어 져야하는 경우

    ... ..98 병의 음료수 병

  • 마지막 절 : 벽에 소다의

    1 병

    소다의 고독한 병 벽을 벽에 소다의

    어떤 병을 떨어 안하면 소다

    1 병!

그래서 생각, 당신은 약간 다른 가사의 마지막 구절을 인쇄 할 루프에 추가하려면 어떻게해야합니까?

// 여기 내 코드입니다. 내가 그것을 실행할 때 병의 수는 12가 아닌 99에서 시작합니다. 어떻게 수정합니까 ??

Scanner user = new Scanner(System.in); 

      int age, beverage; 


      System.out.println("Please type in your age"); 
      age = user.nextInt(); 

      user.nextLine(); 
      System.out.println("Would you like soda or beer? soda=1 beer=2"); 
      beverage = user.nextInt(); 

     if(age<21 || beverage==1) 
      { 
      int bottles = 99; 
      while(1< bottles){ 
       System.out.println(bottles+" of soda on the wall"); 
       System.out.println(bottles+" bottles of soda"); 
       System.out.println("If one of those bottles should fall off the wall"); 
       bottles--; 
       System.out.println("..."+bottles+" bottles of soda on the wall"); 
      if(bottles==1){ 
       System.out.println(bottles+" of soda on the wall"); 
       System.out.println(bottles+" bottles of soda"); 
       System.out.println("If that lone bottle of soda should fall off the wall"); 
       System.out.println("No bottles of soda on the wall"); 
      } 
     } 
    } 
     if(age>=21 && beverage == 2) 
     { 
      int bottles=99; 
      while(1< bottles){ 
       System.out.println(bottles+" of beer on the wall"); 
       System.out.println(bottles+" bottles of beer"); 
       System.out.println("If one of those bottles should fall off the wall"); 
       bottles--; 
       System.out.println("..."+bottles+" bottles of beer on the wall"); 
      if(bottles==1){ 
       System.out.println(bottles+" of beer on the wall"); 
       System.out.println(bottles+" bottles of beer"); 
       System.out.println("If that lone bottle of beer should fall off the wall"); 
       System.out.println("No bottles of beer on the wall"); 
      } 
     } 
    } 

     } 
    } 
+1

'while (1 bottles)'에서 'while (1 bottles)'으로 변경해보십시오. – Mozzie

+0

코딩하는 방식에 문제가 있습니다. 경험이 풍부한 프로그래머로부터 배우고 싶다면 codereview.stackexchange.com에서이 코드를 게시하는 것이 좋습니다. – 6ton

+0

1 병이 생길 때까지 루프에 아무런 포인트도없고 매 사이클마다 조건을 확인하고 2 (포함)까지 끝내고 마지막 줄을 인쇄하십시오. –

답변

0

에 코드를 99 병 인쇄를 시작 않습니다. 마지막 12 병만 보시면 출력 콘솔에 문제가 있습니다. 위로 스크롤을 올려 보거나 다른 콘솔로 시도하거나 파일로 리디렉션 해보십시오 ("> output.txt"를 명령 행 호출에 추가 한 다음 ouput.txt의 내용을 확인하십시오).

+0

이것은 완전한 증거가 아닌 의견입니다. – CinCout

관련 문제