Programing/JAVA

Head First :: 페이지 48쪽 :: BeerSong :: 맥주 99병

2009. 1. 6. 13:34
반응형
Head First(chapter 1 :: p.48 BeerSong)

자바 책중 'head first java'라는 책이 있는 페이지 48쪽의 BeerSong이라는 문제가 있다
아래의 코드가 그 문제이다

public class BeerSong{
	public static void main(String[] args){
		int beerNum = 99;
		String word = "bottles";		//복수형

		while(beerNum > 0){
			if(beerNum==1){
				word = "bottle";		//단수형
			}
			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 > 0){
				System.out.println(beerNum+" "+word+"of beer on the wall");
			}else{
				System.out.println("No more bottles of beer on the wall");
			}
		}
	}
}


위의 코드대로 코딩하면 컴파일도 잘되고 실행도 잘되지만 한가지 흠이 있다고 한다. 어떤 문제가 있는지, 그리고 그 문제를 어떻게해야 고칠수 있는지에 대해서 물어본다.

그런데.. 이 문제를 풀려면 '맥주 99병'이라는 가사를 알아야 풀 수 있다 -_-)
그.래.서
찾아본 '맥주 99병' 가사 노래 제목은'Lyrics of the song 99 Bottles of Beer'이고 http://www.99-bottles-of-beer.net/lyrics.html 의 사이트로 들아가면 가사를 볼수 있다.

아래의 코드는 가사를 보며 수정한 코드다.
클래스명은 임의로  TureBeerSong이라 하고 컴파일 해봤다.

public class TureBeerSong{
	public static void main(String[] args){
		int beerNum = 10;
		String word = "bottle' s";		//복수형

		while(beerNum > 0){
			if(beerNum==1){
				word = "bottle";		//단수형
			}
			System.out.print(beerNum+" "+word+" of beer on the wall, ");
			System.out.println(beerNum+" "+word+" of beer.");
			System.out.print("Take one down and ");
			System.out.println("Pass it around, ");
			beerNum=beerNum-1;

			if(beerNum > 0){
				System.out.println(beerNum+" "+word+" of beer on the wall");
			}else{
				System.out.print("No more bottles of beer on the wall, no more bottles of beer.");
				System.out.println("Go to the store and buy some more, 99 bottles of beer on the wall.");
			}
		}
	}
}


잘 나온다-_-
head first java 책은 정말이지 좋은 책이다. 내용도 좋다. 하지만, 책 번역을 좀 유도리 있게 번역해 주었으면 이렇게까지 짜증이 나지 않았을텐데 좀 아쉽다.
반응형
저작자표시 (새창열림)

'Programing > JAVA' 카테고리의 다른 글

JAVA / JSP :: DBMS별 JDBC 드라이버 사용법  (1) 2010.11.01
utf-8컴파일시 한글 깨짐  (3) 2009.08.30
간단한 servlet 프로그램 작성  (0) 2008.12.16
servlet 사용시 셋팅  (0) 2008.12.16
자바 연산자 연습  (0) 2008.12.07
자바가상머신(JVM) 및 바이트 코드 설명  (0) 2008.12.06
JAVA :: cmd에서 환경변수 잡아주기  (0) 2008.11.25
Java :: 자바 :: JDBC  (0) 2008.11.06
'Programing/JAVA' 카테고리의 다른 글
  • JAVA / JSP :: DBMS별 JDBC 드라이버 사용법
  • utf-8컴파일시 한글 깨짐
  • 간단한 servlet 프로그램 작성
  • servlet 사용시 셋팅
Dongkkase
Dongkkase
개발자로 일하면서 부딪히는 문제풀이가 누군가에게 도움이 되길 바라며
    반응형
  • Dongkkase
    정집사의 개발로그
    Dongkkase
  • 전체
    오늘
    어제
    • All (466) N
      • 금융 (61)
      • Programing (286) N
        • Algorithm (39)
        • API (2)
        • javascript (121)
        • CSS (8)
        • HTML (10)
        • PHP (15)
        • JAVA (27)
        • JSP (17)
        • JSP 예제 (1)
        • IOS (1)
        • Android (1)
        • Sencha Touche (1)
        • bat file, cmd (0)
        • 디버깅 (2)
        • SQL (17)
        • MS-SQL (1)
        • MySQL (12)
        • 보안 (2) N
      • Server (14)
        • Docker (1)
        • Windows (9)
        • Linux (3)
        • jeus (1)
      • Database (6) N
      • IT 일반 (15)
      • 리뷰 (38)
        • Book (17)
        • 제품 (2)
        • 영화 소개 (11)
        • 음악 소개 (7)
      • 잡생각 (33) N
        • 회고 (3)
        • 컬럼 (1) N
        • 자료실 (6)
        • 낙서장 (12)
        • 위시리스트 (2)
        • WOW (1)
        • 덕 (1)
  • 인기 글

  • 최근 댓글

  • 태그

    php
    블로그
    기초
    js패턴
    JavaScript
    디자인패턴
    Java
    자바
    자바스크립트
    SQL
    자바스크립트유틸
    jsp
    읽고 싶은 책
    사고 싶은 책
    iT's MY LiFE
    It
    IT블로그
    IT 관련
    위시리스트
    IT·컴퓨터
Dongkkase
Head First :: 페이지 48쪽 :: BeerSong :: 맥주 99병
상단으로

티스토리툴바