可能重複:
In java, in this program it suddenly stops running properly at a certain point of code? but it compiles? any ideas what could be the issue?爲什麼我的Java程序的最後輸出行不顯示?
import java.io.IOException;
import java.util.*;
public class task2 {
public static void main (String [] args) throws IOException {
int a;
int b;
String y;
String x;
Scanner input = new Scanner(System.in);
System.out.println("Please enter number A:");
a = input.nextInt();
System.out.println("\nPlease enter number B:");
b = input.nextInt();
System.out.println("\nLastly, enter A if you wish it to be the dividor and/or subtractor, or if you wish it to be B, please enter B :");
y=input.next();
System.out.println("\nWhat would you like to do? Multiply (*), Divide (/), Subtract (-) or Add (+)? Please enter the symbol of which process you would like to have completed:");
x=input.next();
if (y.equals("b"+"B")) {
if (x.equals("*")) {
System.out.println("\nThe product of these numbers is:" + (a*b));}
else if (x.equals("/")) {
System.out.println("\nThe quotient of these numbers is:" + (a/b));}
else if (x.equals("+")) {
System.out.println("\nThe sum of these numbers is:" + (a+b));}
else if (x.equals("-")) {
System.out.println("\nThe difference of these numbers is:" + (a-b));
}
}
else
if (y.equals("a"+"A")){
if (x.equals("*")) {
System.out.println("\nThe product of these numbers is:" + (b*a));}
else if (x.equals("/")) {
System.out.println("\nThe quotient of these numbers is:" + (b/a));}
else if (x.equals("+")) {
System.out.println("\nThe sum of these numbers is:" + (b+a));}
else if (x.equals("-")) {
System.out.println("\nThe difference of these numbers is:" + ((b-a)));
}
}
}
}
一個小程序做一組兩個數字的計算。我想要的是用戶輸入他們想要的數字和操作類型(包括訂單)。 計算結果不顯示?有任何想法嗎?所有幫助非常感謝!
請更新您的最後一個問題。 – zengr
您需要:'y.equals(「b」)|| y.equals(「B」)代替'y.equals(「b」+「B」)'。 '「b」+「B」'結果在'「bB」' – zengr
提示:如果你正在學習java。不要經常發佈你的問題。花一些時間調試和理解正在發生的事情。其他方面,你永遠不會明白*它。 – zengr