Posted by : Unknown Mar 26, 2011

import javax.swing.*;
import java.lang.*;
public class konversi {  
    public static String main(long uang) {
        String nama[]={"nol","satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan"};
        String besar[]={"triliun","milyar","juta","ribu",""};              
        if(uang==0) return nama[0];
        long p = 1000000000000l;
        String hasil = "";
        for(int i=0;i < besar.length;i++,p /= 1000)
        {
            if(uang < p) continue;
            long temp = uang / p;              
            boolean seribu = p==1000;
            if(temp>=100) {
                hasil += nama[(int)temp/100] + " ratus ";
                temp %= 100;
                seribu = false;
            }
            if(temp>=11 && temp<=19) {
                hasil += nama[(int)temp-10] + " belas ";
                temp = 0;
                seribu = false;
            }
            if(temp>=10) {
                hasil += nama[(int)temp/10] + " puluh ";
                temp %= 10;
            }
            if(temp > 0) {
             if(seribu && temp==1)
              hasil += "se";
             else
              hasil += nama[(int)temp] + " ";
            }
            uang %= p;
            hasil += besar[i] + " ";
        }
        hasil=hasil.replaceAll("satu ratus", "seratus");
        hasil=hasil.replaceAll("satu belas", "sebelas");
        hasil=hasil.replaceAll("satu puluh", "sepuluh");
        return hasil.trim();
    }

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Have Fun Guys!! - Hatsune Miku - Powered by Blogger - Designed by Johanes Djogan -