I was trying to create a Fahrenheit to Celcius converter. I used the following code for it:
package Kap3;
import javax.swing.*;
public class Upp32{
public static void main(String[] arg){
char d = '\u00B0';
String F = JOptionPane.showInputDialog("Write the temperature in F"+d);
int f = Integer.parseInt(F);
int C = (f-32)*(5/9);
// TEST - JOptionPane.showMessageDialog(null, f);
JOptionPane.showMessageDialog(null, f + "" + d
+ " Degrees Fahrenheit" + "\n Equals to"
+ "\n" + C + d + " Degrees Celcius");
}
}
The problem lays here: JOptionPane.showMessageDialog(null, f + d + " Degrees Fahrenheit"
Somehow it changes the number of Farenheit inputed at the beginning and I don't know why. However if I add +""+
just after f
then it goes away, but I would love to know why it happens.
thank you.
(On other notes, I hope this was a correct way to post something. Got banned for 2 days for my lats thread.)