Convertir Numero Decimal a Romano

no tiene nada que explicar ya se darán cuenta que creamos dos arrays y le damos los valores claves.

package odds; import java.util.*; /** * * @author Reynaldo */ public class Odds { public static void main(String[] args) { int x, i; int Vn[]={ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; String Vc[]={"m","cm","d","cd","c","xc","l","xl", "x","ix","v","iv","i"}; Scanner in = new Scanner( System.in ); while( true ){ x = in.nextInt(); if( x==0 ) break; System.out.printf( "%-4d ", x); i = 0; while( x>0 ){ if( x>=Vn[i] ){ System.out.print( Vc[i] ); x = x - Vn[i]; } else i++; } System.out.println(); } } }

Comentarios