need help, this is my code!
import javax.swing.JOptionPane;
public class Lab2_1 {
public static void main(String[] args) {
int value1=0 ,value2=0 ,operator=0;
String temp4="1";
while(temp4 != "0" ){
String temp1 = JOptionPane.showInputDialog(null,"Please enter first value.");
value1=Integer.parseInt(temp1);
String temp2 = JOptionPane.showInputDialog(null,"Please enter operator.(+,-,*,/)");
String temp3 = JOptionPane.showInputDialog(null,"Please enter second value.");
value2=Integer.parseInt(temp3);
if (temp2 == "+") {
int total=value1+value2;
JOptionPane.showMessageDialog(null,value1+" + "+value2+" = "+total);}
else if (temp2 == "-") {
int total=value1-value2;
JOptionPane.showMessageDialog(null,value1+" - "+value2+" = "+total);}
else if (temp2 == "*") {
int total=value1*value2;
JOptionPane.showMessageDialog(null,value1+" * "+value2+" = "+total);}
else if (temp2 == "/") {
int total=value1/value2;
JOptionPane.showMessageDialog(null,value1+" / "+value2+" = "+total);}
else
JOptionPane.showMessageDialog(null,temp2+" is not a valid operator.");
temp4 = JOptionPane.showInputDialog(null,"Do you still want to continue? Enter 0 to stop.");
}
}
}
why i always get invalid operator only?
+ - * / is not string?