0

how can I solve this error? (not my program but same problem) plss need help

import java.util.Scanner; import javax.swing.JOptionPane; public class Java_Calculator { public static void main(String[] args) { String firstnumber, secondnumber, operation; double num1; double num2; double sum; double sub; double div; double mul; double mod; firstnumber = JOptionPane.showInputDialog ("Enter the first Operand: "); secondnumber = JOptionPane.showInputDialog ("Enter the second Operand: "); operation = JOptionPane.showInputDialog ("Enter the Operator: "); num1 = Double.parseDouble (firstnumber); num2 = Double.parseDouble (secondnumber); sum= num1 + num2; sub= num1 - num2; div= num1 / num2; mul= num1 * num2; mod= num1 % num2; if (operation == '+'){ JOptionPane.showMessageDialog (null, sum);} if (operation == '-'){ JOptionPane.showMessageDialog (null, sub); } if (operation == '/'){ JOptionPane.showMessageDialog (null, div); } if (operation == '*'){ JOptionPane.showMessageDialog (null, mul); } if (operation == '%'){ JOptionPane.showMessageDialog (null, mod); } } }

17th Jul 2016, 4:49 PM
hersonification
1 Respuesta
+ 4
variable 'operation' in your code is string type. so instead of if(operation=='+') use if(operation.equals("+")) at all similar places. I think that should do it
17th Jul 2016, 5:08 PM
Athul Krishna K P