可能重复:
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