This program does the following: First input obtains two numbers from the user, second input if the user inputs (+) symbol the program adds the two numbers together, if the user enters (-) symbol it subtracts the 1st number from the 2nd number. But no results are shown the program just runs and terminates.
import javax.swing.JOptionPane;
public class ObtainNumber {
public static void main(String []args) {
String strNum1 = JOptionPane.showInputDialog("Enter the first number");
String strNum2 = JOptionPane.showInputDialog("Enter the second number");
int num1 = Integer.parseInt(strNum1);
int num2 = Integer.parseInt(strNum2);
String askForOperation = JOptionPane.showInputDialog("What operation needs to be done?");
int sum;
if (askForOperation == "+") {
sum = num1 + num2;
JOptionPane.showMessageDialog(null, "The result of the Addition is " + sum);
}
double subtract;
if (askForOperation == "-") {
subtract = num2 - num1;
JOptionPane.showMessageDialog(null, "The result of the subtraction is " + subtract);
}
}
}