有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何更正这个计算器程序?

这是我的计算器程序

/*program calculator */
import java.util.Scanner;
class calculator

     { public static void main (String args[])
    {   System.out.println("First enter two number , then type Sum for addition, Sub for  subtraction, Mul for multiplication, Div for division");
        int x, y;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter 1st number");
        x = in.nextInt();
               System.out.println("Enter 2nd number");
        y = in.nextInt();
               System.out.println("Enter Sum for addition, Sub for  subtraction, Mul for multiplication, Div for division");
        String z = in.next();
        if (z = "Sum") {a = x + y;};
        if (z = "Sub") {a = x - y;};
        if (z = "Mul") {a = x * y;};
        if (z = "Div") {a = x / y;};
       System.out.println("Result of entered two number = "+z);  
    }
} 

它在语句if (z = "Sum") {a = x + y;};中显示了一个错误“不兼容类型”,我认为它肯定有更多错误。我是初学者。我想让这个程序完美无误,所以它就像一个小计算器一样工作


共 (0) 个答案