为什么赢了';我的Java程序显示的最后一行是什么?
可能重复:为什么赢了';我的Java程序显示的最后一行是什么?,java,eclipse,Java,Eclipse,可能重复: 对一组两个数字进行计算的小程序。我想要的是用户输入他们想要的编号和操作类型(包括顺序)。 计算结果不显示?有什么想法吗?非常感谢大家的帮助 您正在将y和x与A+A和B+B进行比较 你应该做的是: (y.equals(“B”)| y.equals(“B”)) 将管道|用作或语句,不要将它们与+连接起来 这是工作代码 import java.io.IOException; import java.util.Scanner; public class SOScrap {
对一组两个数字进行计算的小程序。我想要的是用户输入他们想要的编号和操作类型(包括顺序)。
计算结果不显示?有什么想法吗?非常感谢大家的帮助 您正在将y和x与A+A和B+B进行比较 你应该做的是:
(y.equals(“B”)| y.equals(“B”))
将管道|
用作或
语句,不要将它们与+
连接起来
这是工作代码
import java.io.IOException;
import java.util.Scanner;
public class SOScrap {
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") || y.equals("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") || y.equals("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)));}}}
}}
请更新您的最后一个问题。您需要:
y.equals(“b”)| y.equals(“b”)
代替y.equals(“b”+“b”)
<代码>“b”+“b”导致“bB”
提示:如果您正在学习java。不要经常发布你的问题。花一些时间调试和理解正在发生的事情。你永远也不会明白。为什么你的节目里有酸橙?我要一些豌豆,加上那些酸橙!回答得好,伙计+1注意你的缩进。另外,考虑只显示固定线的代码,而不是所有的行。
import java.io.IOException;
import java.util.Scanner;
public class SOScrap {
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") || y.equals("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") || y.equals("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)));}}}
}}