-1
I’m making a program where you have a small and simple calculator, basically the user will have the mathematical expressions (+,-,*,/) and you can choose between one of them and then the result will appear on the screen. But for some reason it is not working and it returns as 0 the result.
My code :
int n1 = 20; //o primeiro número
int n2 = 20; //o segundo número
int res = 0;
String op;
op = JOptionPane.showInputDialog("+ " +
"\n - " +
"\n * " +
"\n /");
if(op == "+") {
res = n1+n2; //retorna 0, ao invés de 40.
}
else if(op == "-") {
res = n1-n2;//somente aqui que deve retornar 0.
}
else if(op == "*") {
res = n1*n2;//retorna 0, ao invés de 400.
}
else if(op == "/") {
res = n1/n2;//retorna 0, ao invés de 1.
}
JOptionPane.showMessageDialog(null, "Result : " + res);
Please mark your answer as a solution.
– igventurelli