2
I made a program that converts whole numbers to Roman numbers in Java, but the program does not run.
What can it be?
Follows the code:
import java.util.Scanner;
public class Teste {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
int numero, i;
int vaNum[]= {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
String vaRom[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
while(true){
numero = teclado.nextInt();
if(numero == 0)
break;
System.out.printf("%-4d", numero);
i=0;
while(numero>0){
if(numero >= vaNum[i]){
System.out.println(vaRom[i]);
numero = numero - vaNum[i];
}
}
}
}
I think all you need is the primary symbols of the Roman numbers (I,v,x,L,c, d and m) and how much they represent in decimals and then in which positions they appear when grouped. Doing this makes it easy to convert.
– user28595