Konversi Angka dengan Java


import javax.swing.JOptionPane;

public class KonversiAngka

{

public static void main (String [] args)

{

int n;

int [] bil = new int [7];

String output;

String input;

String choice = “”;

do{

output = “”;

input = JOptionPane.showInputDialog(null,”Masukkan Bilangan : \n (Maksimal 7 digit) “,”Konversi Angka GINA&RINA”,JOptionPane.QUESTION_MESSAGE);

if(input.length() > 7) {

//pesan error

JOptionPane.showMessageDialog(null,”ERROR!!Bilangan lebih dari 7 digit”,”Againts d rule”,JOptionPane.ERROR_MESSAGE);

}

else {

//masukkan ke array

int i = 0;

for (i = 0; i< 7-input.length();i++)

{

bil[i] = 0;

}

for (int j = 0; j < input.length();j++)

{

bil[j+i] = Integer.parseInt(input.charAt(j)+"");

}

int j = 0;

while(j <7)

{

if (bil[j] == 0) {

j++;

}

else {

switch(bil[j]) {

case 1 : {

if((j!=2) && (j!=5) && (j!=6) && (j!=0)) {

output=output+"se";

}

if((j==6) || (j == 0)){

output=output+"satu ";

}

}

break;

case 2 : output=output+"dua ";

break;

case 3 : output=output+"tiga ";

break;

case 4 : output=output+"empat ";

break;

case 5 : output=output+"lima ";

break;

case 6 : output=output+"enam ";

break;

case 7 : output=output+"tujuh ";

break;

case 8 : output=output+"delapan ";

break;

case 9 : output=output+"sembilan ";

break;

}

switch(j) {

case 0 : output = output+"juta ";

break;

case 1 : output = output+"ratus ";

break;

case 2 : {

if(bil[j]!=1) {

output = output+"puluh ";

}

}

break;

case 3 : {

if(bil[j-1]==1) {

output = output+"belas ribu ";

}

else {

output = output+"ribu ";

}

}

break;

case 4 : output = output+"ratus ";

break;

case 5 : {

if(bil[j]!=1) {

output = output+"puluh ";

}

}

break;

case 6 : {

if(bil[j-1]==1) {

output = output+"belas ";

}

}

break;

}

++j;

}

}

JOptionPane.showMessageDialog(null,input+"\n"+output,"HASIL nya nii",JOptionPane.INFORMATION_MESSAGE);

}

choice = JOptionPane.showInputDialog(null,"Mau coba lagi?[Y/T]","COBA-COBA",JOptionPane.QUESTION_MESSAGE);

}

while (choice.equalsIgnoreCase("Y")); {System.exit(0);}

}

}
//silahkan modif sendiri dech yach.selanjut nya terserah anda

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