0
I know I’ve asked a question on the same subject, but another question has arisen. I am developing an application that converts whole numbers to Roman numbers, 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?
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++;
}
}
}
What is the relationship between the latter and the latter: https://answall.com/q/247563/64969?
– Jefferson Quesado
It’s about the same program
– Alexandre
I did not understand the difference between the questions, the titles are very similar. What is the difference between the questions? If the other question is related and important, it is willingly to leave it linked together with a text of yours explaining how they conserve
– Jefferson Quesado
Example: https://answall.com/q/245213/64969
– Jefferson Quesado
In the other the program simply did not work, in this there is only one error ... as quoted above
– Alexandre
You know that the
setText
replaces the previous text, right? So all this iteration is being discarded at the expense of the last operation performed. Why not return toString
for this result set the text? And anyway, your text is confusing me– Jefferson Quesado
Friend, I don’t understand what you mean, I’m just starting in the Java world, can you be clearer please? How to return to String?
– Alexandre
https://answall.com/a/235774/64969
– Jefferson Quesado