我把這個程序,我的第一個有史以來,但我輸入框中的值後,輸出在最後是「0」,而不是減法。我不知道我錯過了什麼。減法不工作在Java程序(缺少的東西)
import java.util.Scanner;
import javax.swing.JOptionPane;
public class PSEUDOCODE_PROGRAM {
public static void main(String[] args) {
Scanner scnr= new Scanner(System.in);
String applesHad = " ";
String applesNeed = " ";
String orangesHad = " ";
String orangesNeed = " ";
int applesTheyHave = 0;
int applesTheyNeed = 0;
int orangesTheyHave = 0;
int orangesTheyNeed = 0;
int applesToOrder = 0;
int orangesToOrder = 0;
applesToOrder = applesTheyNeed - applesTheyHave;
orangesToOrder = orangesTheyNeed - orangesTheyHave;
//Ask produce buyer how many apples are in stock
applesHad= JOptionPane.showInputDialog(null, "How many apples do you have: ");
applesTheyHave = Integer.parseInt(applesHad);
applesHad= JOptionPane.showInputDialog(null, "How many apples do you need: ");
applesTheyNeed = Integer.parseInt(applesHad);
//Ask produce buyer how many oranges are in stock
orangesHad= JOptionPane.showInputDialog(null, "How many oranges do you have: ");
orangesTheyHave = Integer.parseInt(orangesHad);
orangesHad= JOptionPane.showInputDialog(null, "How many oranges do you need: ");
orangesTheyNeed = Integer.parseInt(orangesHad);
JOptionPane.showMessageDialog(null, "You must order " + applesToOrder + " apples and " + orangesToOrder + " oranges!");
你能解釋後的聲明,爲什麼你認爲你可以執行前'applesTheyNeed'和'applesTheyHave'有從輸入它們的值相減? – Tom
沒有問這個問題,下次我會記住這一點。 tks –