fork(4) download
  1. import java.util.Scanner;
  2.  
  3. class Teste {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner teclado = new Scanner(System.in);
  8.  
  9. int[] vaNum = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  10.  
  11. String[] vaRom = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
  12.  
  13. while (true) {
  14.  
  15. int numero = teclado.nextInt();
  16. if (numero == 0) break;
  17. System.out.printf("%-4d ", numero);
  18. int i = 0;
  19. while (numero > 0) {
  20. if (numero >= vaNum[i]) {
  21. System.out.print(vaRom[i]);
  22. numero -= vaNum[i];
  23. } else {
  24. i++;
  25. }
  26. }
  27. System.out.println();
  28. }
  29. }
  30. }
Success #stdin #stdout 0.06s 4386816KB
stdin
4999
237
88
23
0
stdout
4999 MMMMCMXCIX
237  CCXXXVII
88   LXXXVIII
23   XXIII