For a class we are creating a program that takes in a number and spits it out as a roman numeral. This should be really simple, because we don't even have to worry about four being IV. In this program four would be IIII. Anyone have any suggestions on how to do this...? We can't use array's. His instructions state:
This method prints, to the standard output and in purely additive * notation, the Roman numeral corresponding to a natural number. * If the input value is 0, nothing is printed.
I've tried it a couple different ways, and my logic just isn't right. I would really appreciate any suggestions you may have.
Here is what I last tried...
romanDigitChar(val);
if (val - 1000 >= 0)
{
int thousands = val / 1000;
int m_printed = 0;
while ( m_printed < thousands )
{
System.out.print(romanDigitChar(1000));
m_printed++;
}
}
if(val % 100 == 0 && (val/100) >= 5)
{
System.out.print(romanDigitChar(500));
}
if(val % 100 == 0 && (val/100) < 5)
{
int hundreds = val / 100;
int C_printed = 0;
{
while ( C_printed < hundreds )
{
System.out.print(romanDigitChar(100));
C_printed++;
}
}
}
if(val % ROMAN_L == 0)
{
System.out.print(romanDigitChar(50));
}
if(val % 10 == 0 && (val/10) < 5)
{
int tens = val / 10;
int X_printed = 0;
{
while ( X_printed < tens )
{
System.out.print(romanDigitChar(10));
X_printed++;
}
}
}
if(val % 5 == 0)
{
System.out.print(romanDigitChar(50));
}
if(val == 0)
System.out.println("Zero");