source file name: romandemo.java
import java.io.*;
class Roman
{
final char[] ch={'M','D','C','L','X','V','I'};
void roman(int cnt,char ch)
{
for(int n=1;n<=cnt;n++)
System.out.print(ch+" ");
}
}
class romandemo extends Roman
{
void roman(int n)
{
int th,fh,h,ft,tens,fv,s;
th=n/1000;
n=n%1000;
roman(th,ch[0]);
fh=n/500;
n=n%500;
roman(fh,ch[1]);
h=n/100;
n=n%100;
roman(h,ch[2]);
ft=n/50;
n=n%50;
roman(ft,ch[3]);
tens=n/10;
n=n%10;
roman(tens,ch[4]);
fv=n/5;
n=n%5;
roman(fv,ch[5]);
s=n/1;
roman(s,ch[6]);
}
public static void main(String as[])
{
int n;
romandemo ob=new romandemo();
try
{
System.out.println("enter number as year:");
DataInputStream dis=new DataInputStream(System.in);
String s=dis.readLine();
n=Integer.parseInt(s);
System.out.println("Roman conversion:");
ob.roman(n);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
output:
0 Comments
Post a Comment