Change the Input Numbers into Output Letters with Java
Wednesday, November 17, 2010 by: Andy Kurnia Prayoga MadeDescription: This program was made with the Java programming language. By using TextPad compiler. This program is very simple that is to change the input numbers into output letters. For example, we input the number 35 then outputs the resulting program is "Thirty-Five". For more details, follows the source code of this program. Good luck!
import javax.swing.JOptionPane; public class Number_Word{ public String konversi (int angka){ String [] bilangan ={"","satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan","sepuluh","sebelas"}; String temp=" "; if (angka<12){ temp = " " + bilangan[angka]; } else if(angka<20){ temp = konversi(angka-10) + " belas"; } else if(angka<100){ temp = konversi(angka/10) + " puluh" + konversi(angka%10); } else if(angka<200){ temp = "seratus" + konversi(angka-100); } else if(angka<1000){ temp = konversi(angka/100) + " ratus" + konversi(angka%100); } else if(angka<2000){ temp = "seribu"+ konversi(angka-1000); } else if(angka<1000000){ temp = konversi(angka/1000) + " ribu" + konversi (angka%1000); } return temp; } public static void main (String args[]){ do{ try { Number_Word num = new Number_Word(); int konvert = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai")); if (konvert < 0 || konvert >999999) { JOptionPane.showMessageDialog(null,"Angka di luar range!!!","WARNING",JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(null,"Hasil = \n " + konvert + " = " + num.konversi(konvert),"RESULT",JOptionPane.INFORMATION_MESSAGE); } } catch(Exception e){ JOptionPane.showMessageDialog(null,"ERROR","WARNING",JOptionPane.ERROR_MESSAGE); } } while(JOptionPane.showConfirmDialog(null,"Ingin Mengulang??","OPTION",JOptionPane.ERROR_MESSAGE)==JOptionPane.YES_NO_OPTION); } }