变量code和code2具有相同的值,但不相等

问题描述

class income
{
    public static void calc( )
    {
        Scanner sc= new Scanner(system.in);
        System.out.println("Enter employee code");
        String code= sc.next();
        System.out.println("Confirm employee code");
        String code2= sc.next();
        System.out.println("employee code: " + code);
        System.out.println("employee code: " + code2);
        if (code2==code)
        {
        System.out.println("Enter salary");
        int sal=sc.nextInt();
        double hra = 0.2 * sal;
        double da= 0.55 * sal;
        double grosssal= sal + da + hra;
        double pf = 0.06* grosssal;
        double netsal= grosssal-pf;
        System.out.println("net salary(gross salary - pf) ="+ netsal);
        double taxd;
        if (grosssal*12<=100000)
        { taxd = 0;
        }
        else if (grosssal*12<=500000) 
        {
            taxd= 1000 + 0.1*((grosssal*12)-100000);
        }
        else
        {
         taxd= 5000 + 0.2*((grosssal*12)-500000);
        }
        double monthsal = netsal- (taxd/12);
        System.out.println("employee code: " + code);
        System.out.println("montly salary(gross salary - pf - tax)="+ monthsal);
        System.out.println("tax deduction(annual)="+ taxd);}
                else if(code!=code2)
        {System.out.println("Invalid input");}
    }
        
    }

在上面的代码中,输出始终是无效输入(这意味着计算机认为变量不等于0,即使两个值都相同,也会发生这种情况 变量code和code2具有相同的值,但是不相等

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...