当我运行我的代码时,它会正常工作,直到它提出问题“您想要使用哪种操作(sum,subst,multi,div)”。无论用户选择什么,我的程序都没有回应!这个非常简单的代码有什么问题
这是怎么发生的?
import java.util.Scanner;
import java.io.*;
public class three3 {
public static void main (String[] args) {
int x;
int y;
int opera;
String oper;
Scanner in = new Scanner (System.in);
System.out.println(" write the first number ");
x = in.nextInt();
System.out.println(" write the second number ");
y = in.nextInt();
System.out.println(" which operation do you want to use from (sum , subst , multi , div)");
oper = in.nextLine();
if (oper == "sum") {
opera=x+y;
System.out.println(" the sum of two numbers is " + opera);
}
if (oper == "subst") {
opera = x - y;
System.out.println(" the subtraction of two numbers is " + opera);
}
if (oper == "multi") {
opera = x * y;
System.out.println(" the multi of two numbers is " + opera);
}
if (oper == "div") {
opera = x/y;
System.out.println(" the division of two numbers is " + opera);
}
}
}
这不是正确的答案 – gurghet
@gurghet我错过了胡安的回答中的错误,但是我正在接受的观点仍然是意外行为的一个原因。 – runDOSrun
没有*错误的*回应。有*没有*回复 – gurghet