2
請幫忙。我對此很新,而且我非常需要這個。我需要創建一個程序,讓它可以選擇加法或減法。這是我目前的程序:基本加減選項
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);
}
}
}
怎麼了?即使在第一步,我也無法得到它。
重新格式化的代碼;如果不正確請回復。 – trashgod 2010-12-04 02:27:45
請具體說明您的問題。 – 2010-12-04 02:29:30