java angka terbilang

 

Bismillah

q> Langsung to coding


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package testingcode;

/**
*
* @author saifi
*/
public class Terbilang {

private static String bilangLong(Long angka) {
String[] ucapan = {"", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas"};

if (angka.longValue() < 12L) {
System.out.println("masuk < 12L");
return " " + ucapan[angka.intValue()];
}
if (angka.longValue() < 20L) {
System.out.println("masuk < 20L");
return bilangLong(Long.valueOf(angka.longValue() - 10L)) + " Belas";
}
if (angka.longValue() < 100L) {
System.out.println("masuk < 100L");
return bilangLong(Long.valueOf(angka.longValue() / 10L)) + " Puluh" + bilangLong(Long.valueOf(angka.longValue() % 10L));
}
if (angka.longValue() < 200L) {
System.out.println("masuk < 200L");
return " Seratus" + bilangLong(Long.valueOf(angka.longValue() - 100L));
}
if (angka.longValue() < 1000L) {
System.out.println("masuk < 1000L");
return bilangLong(Long.valueOf(angka.longValue() / 100L)) + " Ratus" + bilangLong(Long.valueOf(angka.longValue() % 100L));
}
if (angka.longValue() < 2000L) {
System.out.println("masuk < 2000L");
return " Seribu" + bilangLong(Long.valueOf(angka.longValue() - 1000L));
}
if (angka.longValue() < 1000000L) {
System.out.println("masuk < 1000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000L)) + " Ribu" + bilangLong(Long.valueOf(angka.longValue() % 1000L));
}
if (angka.longValue() < 1000000000L) {
System.out.println("masuk < 1000000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000000L)) + " Juta" + bilangLong(Long.valueOf(angka.longValue() % 1000000L));
}
if (angka.longValue() < 1000000000000L) {
System.out.println("masuk < 1000000000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000000000L)) + " Milyar" + bilangLong(Long.valueOf(angka.longValue() % 1000000000L));
}
if (angka.longValue() < 1000000000000000L) {
System.out.println("masuk < 1000000000000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000000000000L)) + " Trilyun" + bilangLong(Long.valueOf(angka.longValue() % 1000000000000L));
}

return "";
}

public static void main(String[] args) {
Long angka = 4578000L;
System.out.println("Angka = " + angka);
String terbilang = bilangLong(angka);
System.out.println("Terbilang = " + terbilang);
}

}

q> Hasil :
Selection_833

Alhamdulillah

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s