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

Java 如何更正这个计算器程序?,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

这是我的计算器程序

/*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;}中显示错误“不兼容类型”我想它肯定有更多的错误。我是初学者。我想使这个程序完美无误,因此它的工作原理与小型计算器完全相同。

您可以使用“==”进行比较 (并打印结果a而不是z)


谢谢用户3804188
if (z.equals("Sum")) {a = x + y;};
if (z.equals("Sub")) {a = x - y;};
if (z.equals("Mul")) {a = x * y;};
if (z.equals("Div")) {a = x / y;};
System.out.println("Result of entered two number = " + a);