Saturday, February 9, 2013

Decimal to Roman number conversion

import java.util.*;
class dectoroman
{
    public static void main(String arg[])
    {
        Scanner ob = new Scanner(System.in);
        String R[ ]={"C", "XC", "L", "XL", "X", "IX","V", "IV","I"};
        int x[ ]={100,90, 50, 40, 10, 9, 5, 4, 1};
        int d, i;
        String t="";
        System.out.println("Enter an integer number ");
        d=ob.nextInt();
        for(i=0;i
<R.length;i++)

        {    
            while(d<=x[i])
            {
                d = d - x[i];
                t = t + R[i];
            }
        }
        System.out.println("Roman number is = "+ t);
    }
}

2 comments:

Anonymous said...

while(d>=x[i])
{
d = d - x[i];
t = t + R[i];
}

sir the program will run only on this condition

Unknown said...

while(d<=x[i])

this program is for numbers less than 100