我的程序有問題。程序顯示第一個JOption消息對話框,但是當你輸入一個值時,它不能顯示第二個對話框?基本計算器
import java.util.Scanner;
import javax.swing.JOptionPane;
public class javaCalculator
{
public static void main(String[] args)
{
int num1;
int num2;
String operation;
Scanner input = new Scanner(System.in);
JOptionPane.showInputDialog(null,"please enter the first number");
num1 = input.nextInt();
JOptionPane.showInputDialog(null,"please enter the second number");
num2 = input.nextInt();
JOptionPane.showInputDialog(null,"Please enter operation");
operation = input.next();
if (operation.equals ("+"))
{
JOptionPane.showMessageDialog(null,"your answer is" + " " + (num1 + num2));
}
if (operation.equals ("-"))
{
JOptionPane.showMessageDialog(null,"your answer is" + " " + (num1 - num2));
}
if (operation.equals ("/"))
{
JOptionPane.showMessageDialog(null,"your answer is" + " " + (num1/num2));
}
if (operation.equals ("*"))
{
JOptionPane.showMessageDialog(null,"your answer is" + " " + (num1 * num2));
}
}
}
然後操作可能*不*等於任何操作字符串 - 什麼是* *是真的嗎? (另外,考慮使用'System.out.println'作爲控制檯應用程序..你正在從控制檯讀取數據,所以不妨寫信給它: - /) – 2013-02-06 01:54:34
而且,*這個程序是如何啓動的?用'java'或'javaw'? – 2013-02-06 02:01:16