请帮助解决这个问题。我对此很陌生,我非常需要这个。我需要创建一个程序,让您可以选择加法或减法。这是我目前的程序:
import javax.swing.JOptionPane;
public class RationalZ {
public static void main(String args[]) {
JOptionPane.showMessageDialog(null,
"Enter the letter A for Addition and B Subtraction");
String choice = JOptionPane.showInputDialog(
"A=Addition B=Subtraction");
if (choice == "a") {
String strNum1 = JOptionPane.showInputDialog(
"Enter a Number");
String strNum2 = JOptionPane.showInputDialog(
"Enter a second number");
int aNum1 = Integer.parseInt(strNum1);
int aNum2 = Integer.parseInt(strNum2);
JOptionPane.showMessageDialog(null, aNum1 + aNum2);
System.exit(0);
} else {
System.exit(0);
}
}
}
怎么了?即使在第一步我也无法得到它。