Pages

Powered by Blogger.

Friday, January 16, 2015

Menampilkan gabungan kata yang merupakan konversi dari angka yang dimasukkan (angka sampai ratusan ribu) dengan java

Membuat kode program dengan menampilkan gabungan kata yang merupakan konversi dari angka yang dimasukkan (angka sampai ratusan ribu).
Misal :
Input:  2401 (integer)

Output: dua ribu empat ratus satu.

kode program
  Scanner input = new Scanner(System.in);
        int n;
        System.out.println("===Program peubah ongko nang krama alus===");
        System.out.print("nglebetaken ongko 1 ngantos 100000 : ");
        n=input.nextInt();
        String z;
        z=Integer.toString(n);
        int digit=z.length();
        switch (digit){
            case 6 : digit6(n);break;
            case 5 : digit5(n);break;
            case 4 : digit4(n);break;
            case 3 : digit3(n);break;
            case 2 : digit2(n);break;
            case 1 : if(n!=0){
                        digit1(n);
            }
                    else{
                        nilai(n);break;
                    }
        }
     }

    public static int nilai (int n){
            switch(n){
                case 0 : System.out.print("nol ");break;
                case 1 : System.out.print("setunggal ");break;
                case 2 : System.out.print("kalih ");break;
                case 3 : System.out.print("tigo ");break;
                case 4 : System.out.print("sekawan ");break;
                case 5 : System.out.print("gangsal ");break;
                case 6 : System.out.print("enem ");break;
                case 7 : System.out.print("pitu");break;
                case 8 : System.out.print("wolu ");break;
                case 9 : System.out.print("sanga ");break;
                case 10 :System.out.print("sedoso ");break;
                case 11 :System.out.print("sewelas ");break;
                case 12 :System.out.print("kaleh welas ");break;
                case 13 :System.out.print("tigo welas ");break;
                case 14 :System.out.print("sekawan welas ");break;
                case 15 :System.out.print("gangsal welas ");break;
                case 16 :System.out.print("enem welas ");break;
                case 17 :System.out.print("pitulas ");break;
                case 18 :System.out.print("wolulas ");break;
                case 19 :System.out.print("songolas ");break;
            }
            return n;
    }

    public static int digit6 (int x){
        int hasil, sisa;
        hasil=x/100000;
        sisa=x%100000;
        if(hasil==7){
            System.out.print("pitung doso wewu");
            if(sisa>=0 && sisa<1000){
                System.out.print("doso ewu");
            }
        }
        if(hasil!=1){
            nilai(hasil);
System.out.print("doso ewu");
            if(sisa>=0 && sisa<1000){
                System.out.print("doso ewu");
            }
        }

        digit5(sisa);
        return hasil;
    }

    public static int digit5 (int x){
        int hasil,sisa;
        hasil=x/10000;
        sisa=x%10000;
        if(hasil!=0){
            if(hasil==7){
                x/=1000;
                nilai(x);
                System.out.print(" pitung doso ewu ");
                sisa=sisa%1000;
                digit4b(sisa);
            }
            else{
                nilai(hasil);
                System.out.print(" ");
                if(sisa>=0 && sisa<1000){
                    System.out.print(" doso ewu ");
                }
            }
        }
        if(hasil!=1){
            digit4b(sisa);
        }
        return hasil;
    }

    public static int digit4b(int x){
        int hasil, sisa;
        hasil=x/1000;
        sisa=x%1000;
        if(hasil!=0){
            nilai(hasil);
            System.out.print(" ewu ");
        }
        digit3(sisa);
        return hasil;
    }

    public static int digit4(int x){
        int hasil, sisa;
        hasil=x/1000;
        sisa=x%1000;
        if(hasil!=0){
            if(hasil==7){
            System.out.print(" pitung ewu ");
            } else{
            nilai(hasil);
            System.out.print(" ewu ");
            }
        }
        digit3(sisa);
        return hasil;
    }

    public static int digit3(int x){
        int hasil,sisa;
        hasil=x/100;
        sisa=x%100;

        if(hasil!=0){
            if(hasil==7){
            System.out.print(" pitung atus ");
            }
            else{
                nilai(hasil);
            System.out.print(" atus ");
            }
        }
            digit2(sisa);
        return hasil;
    }

    public static int digit2 (int x){
        int hasil,sisa;
        hasil=x/10;
        sisa=x%10;
        if(hasil==1){
            nilai(x);
        }
        if(hasil!=0 && hasil!=1){
            nilai(hasil);
            System.out.print(" doso ");
        }
        if(hasil!=1){
            digit1(sisa);
        }
        return hasil;
    }

    public static int digit1 (int x){
        int hasil=x;
        if(x!=0){
            nilai(hasil);
        }
        return hasil;

    }
}

No comments:

Post a Comment

 

Blogger news

Blogroll

About