Convert Roman numerals [duplicate]

this question already has an answer here : convert Roman numerals to Java (1 answer) Closed for 3 years.

I know I have already asked a question on the same subject, but another question arose. I am developing an application that converts integers to Roman numerals, as you can see in the code below ... But, jTextField1 is returning other numbers, as you can see in the image, does anyone have any idea what it might be? insert the description of the image here

    private void btnConverterActionPerformed(java.awt.event.ActionEvent evt) {                                             
        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"};

        int numero = Integer.parseInt(jTextField2.getText());
        System.out.printf("%-4d ", numero);
        int i = 0;
        while (numero > 0) {
            if (numero >= vaNum[i]) {
                jTextField1.setText(vaRom[i]);
                numero -= vaNum[i];
            } else {
                i++;
            }
        }
    }  
Author: Alexandre, 2017-10-20

1 answers

private void btnConverterActionPerformed(java.awt.event.ActionEvent evt) {                                             
    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"};

    public String resposta;

    int numero = Integer.parseInt(jTextField2.getText());
    System.out.printf("%-4d ", numero);
    int i = 0;
    while (numero > 0) {
        if (numero >= vaNum[i]) {
            resposta += vaRom[i];
            numero -= vaNum[i];
        } else {
            i++;
        }
    }

    jTextField1.setText(resposta);
}
 0
Author: Costamilam, 2017-10-20 04:28:22