Membuat sebuah program untuk mengubah angka desimal ke angka romawi menggunakan java !
import java.util.*;
public class KonversiDesimalToRomawi
{
public static void main (String args[])
{
int bil;
String tampil="";
//inisialisasi berupa array
String [] biasa = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
String [] sepuluh = {"","X","XX","XXX","XL"};
String [] limapuluh = {"","L","LX","LXX","LXXX","XC"};
String [] seratus = {"","C","CC","CCC","CD"};
String [] limaratus = {"","D","DC","DCC","DCCC","CM"};
String [] seribu = {"","M","MM","MMM","MV","V"};
// inputan dari keyboard
System.out.println("================================================");
System.out.println("= Konversi Bilangan Desimal ke Bilangan Romawi =");
System.out.println("================================================");
System.out.println("");
System.out.print(" Masukkan Bilangan Desimal Di Bawah 5000 : ");
Scanner obj = new Scanner(System.in);
bil = obj.nextInt();
System.out.println("");
//kondisi dimana angka tidak lebih dari 5000
if (bil>5000)
{
System.out.println("");
System.out.println(" Angka Desimal Yang Di Inputkan Harus Di Bawah 5000");
System.out.println("");
}
else
{
//defenisi
int lmrts = bil % 1000;
int srts = lmrts % 500;
int lmpl = srts % 100;
int spl = lmpl % 50;
int ak = spl % 10;
int a = bil / 1000;
tampil += ""+seribu[a];
//aturan konversi desimal ke romawi
if ( (lmrts >=900) && (lmrts <= 999))
{
tampil += "CM";
if( (lmpl >= 90) && (lmpl <= 99) )
{
tampil += "XC";
int f= ak/1;
tampil += ""+biasa[f];
}
else
{
int d = lmpl/50;
tampil += ""+limapuluh[d];
int e = spl/10;
tampil += ""+sepuluh[e];
int f= ak/1;
tampil += ""+biasa[f];
}
}
else
{
int b = lmrts/500;
tampil += ""+limaratus[b];
if ( (srts >= 400)&& (srts <= 499) )
{
tampil += "CD";
if( (lmpl >= 90) && (lmpl <= 99) )
{
tampil += "XC";
int f= ak/1;
tampil += ""+biasa[f];
}
else
{
int d = lmpl/50;
tampil += ""+limapuluh[d];
int e = spl/10;
tampil += ""+sepuluh[e];
int f= ak/1;
tampil += ""+biasa[f];
}
}
else
{
int c = srts/100;
tampil += ""+seratus[c];
if((lmpl >= 90)&&(lmpl <= 99))
{
tampil += "XC";
int f= ak/1;
tampil += ""+biasa[f];
}
else
{
int d = lmpl/50;
tampil += ""+limapuluh[d];
int e = spl/10;
tampil += ""+sepuluh[e];
int f= ak/1;
tampil += ""+biasa[f];
}
}
}
System.out.println(" Bilangan Desimal : " + bil);
System.out.println(" Bilangan Romawi : " + tampil);
System.out.println("");
}
}
}
Hasil eksekusinya :
Mengubah Angka Desimal ke Angka Romawi
Langganan:
Posting Komentar (Atom)
2 komentar:
tengkyu very much bang programnya... sukses selalu.. :)
ya terima kasih atas kunjungannya...
semoga programnya berguna...
Posting Komentar