2013. 7. 25. 16:28



'java' 카테고리의 다른 글

로또생성기  (0) 2013.07.25
세로형 성적 그래프  (0) 2013.07.25
숫자를 한글로 변환(금액단위)  (0) 2013.07.25
검색어 발견 카운터  (0) 2013.07.25
빼기연산으로 몫과 나머지 구하기  (0) 2013.07.25
Posted by 1+1은?
2013. 7. 25. 16:27


static void getResult() {
    // 요구사항] 숫자를 입력받은뒤 한글로 출력하시오
    // 입력] ₩12,345
    // 출력] 금 일만이천삼백사십오원
    // 조건] 숫자는 7자리 이내
 
    // input//
    Scanner scan = new Scanner(System.in);
    String str = scan.nextLine();
 
    // validation//
    int value = Integer.parseInt(str);
    System.out.printf("입력하신 금액은 ... \n ₩%,d 입니다.\n", value);
    if (str.length() > 7) {
        System.out.println("입력가능 범위 초과(out of range)");
        return;
    }
 
    // output//
    System.out.print("금 ");
 
    for (int i = 0; i < str.length(); ++i) {
        System.out.print(translate(str.charAt(i), (str.length()) - i));
    }
 
    System.out.println(" 원");
}
 
static String translate(int number, int level) {
    String result = "";
    String won = "";
    String dan = "";
 
    switch (number) {
    case 48: won = ""; break;
    case 49: won = "일"; break;
    case 50: won = "이"; break;
    case 51: won = "삼"; break;
    case 52: won = "사"; break;
    case 53: won = "오"; break;
    case 54: won = "육"; break;
    case 55: won = "칠"; break;
    case 56: won = "팔"; break;
    case 57: won = "구"; break;
    }
    switch (level) {
    case 7: dan = "백만"; break;
    case 6: dan = "십만"; break;
    case 5: dan = "만"; break;
    case 4: dan = "천"; break;
    case 3: dan = "백"; break;
    case 2: dan = "십"; break;
    case 1: dan = ""; break;
    }
    result = won + dan;
    return result;
}
 
 
123456
입력하신 금액은 ... 
 ₩123,456 입니다.
금 일십만이만삼천사백오십육 원


'java' 카테고리의 다른 글

세로형 성적 그래프  (0) 2013.07.25
Callendar 클래스 없이 달력만들기  (0) 2013.07.25
검색어 발견 카운터  (0) 2013.07.25
빼기연산으로 몫과 나머지 구하기  (0) 2013.07.25
별찍기  (0) 2013.07.25
Posted by 1+1은?
2013. 7. 25. 16:26


static void getResult() {
    // 힌트] indexOf(검색어, startIndex);//**startIndex
    // 찾음 -> 찾음 -> 찾음 -> 못찾으면 break
    // index용 변수는 -1이 디폴트
 
    String str = "Java란 블라블라Java 블라블라Java Java블라블Java...";
    String inputTxt = "Java";
 
    int count = 0;
    int where = str.indexOf(inputTxt, 0);
    while (true) {
 
        if (where < 0) {
            System.out.printf("%s가 발견된 횟수는 총 %d회입니다.", inputTxt, count);
            break;
        } else {
            count += 1;
            where = str.indexOf(inputTxt, where + inputTxt.length());
        }
    }
}


'java' 카테고리의 다른 글

Callendar 클래스 없이 달력만들기  (0) 2013.07.25
숫자를 한글로 변환(금액단위)  (0) 2013.07.25
빼기연산으로 몫과 나머지 구하기  (0) 2013.07.25
별찍기  (0) 2013.07.25
배열 + 제어문으로 중복값 찾기  (0) 2013.07.25
Posted by 1+1은?
2013. 7. 25. 16:25



static void getResult(double a, double b) {
    double cnt = 0;
 
    while (a > 0) {
        a = a - b;
         
        if (a < 0) { //나머지는 0보다 작을 수 없음
            a = a + b;
            break;
        }
         
        cnt++;
    }
    System.out.println("몫 = " + cnt + ", 나머지 = " + a);
}
 
 
getResult(10, 3);
몫 = 3.0, 나머지 = 1.0

나누어질 값 a를 나눌값 b로 뺄셈하여 그 횟수(cnt)와 나머지(mod)를 구하는 식

'java' 카테고리의 다른 글

숫자를 한글로 변환(금액단위)  (0) 2013.07.25
검색어 발견 카운터  (0) 2013.07.25
별찍기  (0) 2013.07.25
배열 + 제어문으로 중복값 찾기  (0) 2013.07.25
자바 리플렉션 사용하기 (Using Java Reflection)  (0) 2013.07.25
Posted by 1+1은?
2013. 7. 25. 16:25



static void showStar() {
    for (int j=1; j<=5; j++) {
        for (int i=4; i>=j; i--) {
            System.out.print(" ");
        }
  
        for (int i=1; i<=j; i++) {
            System.out.print("*");
        }
        System.out.println();
    }
}
  
  
    *
   **
  ***
 ****
*****

static void showStar() {

    for (int j=1; j<=5; j++) {
        for (int i=4; i>=j; i--) {
            System.out.print(" ");
        }
  
        for (int i=1; i<=(j*2)-1; i++) {
            System.out.print("*");
        }
        System.out.println();
    }
}
  
  
    *
   ***
  *****
 *******
*********
static void showStar() {

    for (int j=1; j<=5; j++) {
        for (int i=1; i<=5-j; i++) {
            System.out.print(" ");
        }
        for (int i=1; i<=(j*2)-1; i++) {
            System.out.print("*");
        }
        System.out.println();
    }
  
    for (int j=4; j>=1; j--) {
        for (int i=0; i<=4 - j; i++) {
            System.out.print(" ");
        }
        for (int i=1; i<=(j*2)-1; i++) {
            System.out.print("*");
        }
        System.out.println();
    }
}
  
  
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

static void showStar() {

    for (int j=1; j<=5; j++) {
        for (int i=4; i>=j; i--) {
            System.out.print(" ");
        }
         
        if(j<5) {
            for (int i=1; i<=(j*2)-1; i++) {
                if(i==1 || i==(j*2)-1)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
        } else {
            for (int i=1; i<=(j*2)-1; i++) {
                System.out.print("*");
            }
        }
        System.out.println();
    }
}
  
  
    *
   * *
  *   *
 *     *
*********

Posted by 1+1은?