markpanther
Technical User
Can anyone help me w this code some
Im tryin to convert digits to roman numerals and vice versa
Im tryin to convert digits to roman numerals and vice versa
Code:
import javax.swing.JOptionPane;
[COLOR=red] public class ExerRoman {
String arabicString = new String(arabic); String romanString = new String("");
String aLen = arabicString.length;
int n = 1;
while ( n <= aLen ){
int i = ( aLen - n );
int s = parseInt(arabicString.charAt(i));
if (n == 1)
{ romanString = RomanI[s]; }
if (n == 2)
{ romanString = RomanX[s]+romanString; } if (n == 3)
{ romanString = RomanC[s]+romanString; } if (n == 4)
{ romanString = RomanM[s]+romanString; } n++;
return romanString;}
//read in first user input
String arabic =
JOptionPane.showInputDialog( "Enter first number" );
[/color][COLOR=blue]
int RomanI = new Array("","I","II","III","IV","V","VI","VII","VIII","IX");
int RomanX = new Array("","X","XX","XXX","XL","L","LX","LXX","LXXX","XC");
int RomanC = new Array("","C","CC","CCC","CD","D","DC","DCC","DCCC","CM");
int RomanM = new Array("","M","MM","MMM","IV","V","VI","VII","VIII","IX");
[/color]
JOptionPane.showMessageDialog ( null, "The product is " + romanString, "Romanized", JOptionPane.PLAIN_MESSAGE );}