该程序在 BlueJ 中,它没有在 if else 中看到任何情况并直接转到最后一个 else 语句?

The program is in BlueJ it is not seeing any case in if else and directly going to the last else statement?

public class trigo { 

    public double conversion(String a) {

        String func="",f=a,sin="sin",cos="cos",tan="tan",cosec="cosec",cot="cot",sec="sec";
        f=f.trim();
        double p=0,z=0;
        try {
            p=Double.valueOf(f);
        } catch(Exception e) {
            func=f.substring(0,3);
            f=f.substring(3,f.length());

            try {
                p=Double.valueOf(f);
            } catch(Exception d) {
                func=func.concat("ec");
                f=f.substring(2,f.length());
                p=Double.valueOf(f);
            }
        }'problem starts here'

        if(func=="")
            z=p;
        else if(func=="sin")
            z=Math.sin(p);
        else if(func=="cos")
            z=Math.cos(p);
        else if(func.=="tan")
            z=Math.tan(p);
        else if(func=="cosec")
            z=1/Math.sin(p);
        else if(func=="sec")
            z=1/Math.cos(p);
        else if(func=="cot")
            z=1/Math.tan(p);
        else
            System.out.println("please check for spelling mistake");
        'ends here'
        System.out.print(z);
    }
}

在此代码中,其输出为 "please check for spelling mistake"

func 从未分配,因为您的整个逻辑都放入了 catch 块。

catch(Exception e) {
            func=f.substring(0,3);
            f=f.substring(3,f.length());

            try {
                p=Double.valueOf(f);
            } catch(Exception d) {
                func=func.concat("ec");
                f=f.substring(2,f.length());
                p=Double.valueOf(f);
            }
        }

只有输入解析失败才会运行

一个简单的调试(甚至是 println)应该可以让您了解发生了什么。