source code name: RomanConversionDemo.java
class RomanConversionDemo
{
void roman(int n, char ch)
{
for(int i=1;i<=n;i++)
System.out.print(ch+" ");
}
public static void main(String[] arg)
{
int th=0,fh=0,h=0,ft=0,ten=0,fv=0,s=0;
int n;
RomanConversionDemo ob=new RomanConversionDemo();
n=Integer.parseInt(arg[0]);
th=n/1000;
ob.roman(th,'M');
n=n%1000;
fh=n/500;
ob.roman(fh,'D');
n=n%500;
h=n/100;
ob.roman(h,'C');
n=n%100;
ft=n/50;
ob.roman(ft,'L');
n=n%50;
ten=n/10;
ob.roman(ten,'X');
n=n%10;
fv=n/5;
ob.roman(fv,'V');
n=n%5;
s=n;
ob.roman(s,'I');
}
}
output:
F:\Nalawade\java1819>javac RomanConversionDemo.java
F:\Nalawade\java1819>java RomanConversionDemo
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at RomanConversionDemo.main(RomanConversionDemo.java:16)
F:\Nalawade\java1819>java RomanConversionDemo 1500
M D
F:\Nalawade\java1819>java RomanConversionDemo 1988
M D C C C C L X X X V I I I
F:\Nalawade\java1819>java RomanConversionDemo 2345
M M C C C X X X X V
0 Comments
Post a Comment