728x90
반응형

값을 입력 받으면 콤마로 나누어져서 22345라는 값을 입력 받으면 2십2만3백4십5라는 값을 출력하게 되는데요

이 소스는 숫자단위 경이넘어가게 되면 입력받은 숫자단위를 끝까지 출력하지 못합니다.

이것을 String형으로 바꾸어 주어야 하는데 자꾸 에러가 나네요

최대한 빨리 도와주시면 감사하겠습니다. 

 

import java.text.*;
import java.io.*;

public class test_04 {
 
 public String ss()throws IOException{
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("수를 입력 하세요 : ");
  double db = Double.parseDouble(br.readLine());

  DecimalFormat d = new DecimalFormat("################################,#");
       
        String[] unit = new String[]{"","십","백","천","만","십","백","천","","십","백","천","조","십","백","천","경","십","백","천","해","십","백","천","자","십","백","천"};
        String[] str = d.format(db).split(",");
  String result = "";
        int cnt = 0;
        for(int i=str.length;i>0;i--) {
            if(Integer.parseInt(str[i-1]) != 0) {
                result = String.valueOf(Integer.parseInt(str[i-1])) + unit[cnt] + result;
            }
            cnt++;
        }
  return result;
 }
    public static void main(String[] arg)throws IOException {
  test_04 aa = new test_04();
  String result = aa.ss();
        System.out.println(result + "원");
    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

import java.text.*;
import java.io.*;

public class test_04 {
 
 public String ss()throws IOException{
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("수를 입력 하세요 : ");
  String db = br.readLine();

     
        String[] unit = new String[]{"","십","백","천","만","십","백","천","","십","백","천","조","십","백"," 천","경","십","백","천","해","십","백","천","자","십","백","천"};
        char[] str = db.toCharArray();
  String result = "";
        int cnt = 0;
       for(int i=str.length;i>0;i--) {
            if(str[i-1] != '0') {
                result = str[i-1] + unit[cnt] + result;
            }
            cnt++;
        }
  return result;
 }
    public static void main(String[] arg)throws IOException {
  test_04 aa = new test_04();
  String result = aa.ss();
        System.out.println(result + "원");
    }

}

 

728x90
반응형
블로그 이미지

nineDeveloper

안녕하세요 현직 개발자 입니다 ~ 빠르게 변화하는 세상에 뒤쳐지지 않도록 우리모두 열심히 공부합시다 ~! 개발공부는 넘나 재미있는 것~!

,