/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package romawi;
import java.util.*;
public class Main {
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.print("Masukkan bilangan desimal : ");
Scanner obj = new Scanner(System.in);
bil = obj.nextInt();
//kondisi dimana angka tdk lebih dari 5000
if (bil>5000)
{
System.out.println("Maaf.., Angka Desimal Yang Di "+
"Inputkan Harus
Di Bawah 5000");
}
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";
//90
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];
//400
if ( (srts >=
400)&& (srts <= 499) )
{
tampil +=
"CD";
//90
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("Maka angka Romawinya
" + bil+ " : " + tampil );
}
}
}
Komentar
Posting Komentar