jump to navigation

Konversi Bilangan Romawi Ke Desimal April 21, 2008

Posted by yasinisasi in Java.
trackback

Program sederhana ini berfungsi untuk mengkonversi bilangan romawi ke bilangan desimal biasa. Jika user memasukkan inputan yang salah, maka program juga akan mengeluarkan output yang salah. Jika ingin membuat program yang dapat mencegah user memasukkan inputan yang silahkan berikan komentar anda.
import javax.swing.*;
public class RomawiFinal {
private static int Nlai(char Hrf){
char[]Romawi={‘s’,’y’,’m’,’d’,’c’,’l’,’x’,’v’,’i’};
int[]value={10000,5000,1000,500,100,50,10,5,1};
for(int a=0;a<Romawi.length;a++)
if(Hrf==Romawi[a])return value[a];
return 0;
}
public static void main(String []args){
char[]Hrf=JOptionPane.showInputDialog(null,”Masukkan bilangan romawi”).toLowerCase().toCharArray();
int Hsl=Nlai(Hrf[Hrf.length-1]);
for(int i=1;i=Nlai(Hrf[Hrf.length-i]))Hsl+=Nlai(Hrf[Hrf.length-1-i]);
else Hsl -=Nlai(Hrf[Hrf.length-1-i]);
}
JOptionPane.showMessageDialog(null,String.valueOf(Hrf)+” Setelah dikonversi menjadi “+Hsl);
}
}

Comments»

1. Oliph - October 25, 2009

thakz a lot

==>sama sama

2. atlo - January 13, 2010

GK MAU

3. andy - January 16, 2010

thanks for your coding…

yasinisasi - January 8, 2011

you’re welcome


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

%d bloggers like this: