错误:在类Calculate中找不到主方法,请将main方法定义为:public static void main(String [] args) [英] Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args)

查看:2531
本文介绍了错误:在类Calculate中找不到主方法,请将main方法定义为:public static void main(String [] args)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助主方法,我收到此错误:

I need help with the main method, I'm getting this error:

Error: Main method not found in class Calculate, please define the main method as:
    public static void main(String[] args)

这是代码:

class Calculate {

private double fn;
private double sn;
private char op;

public void setNumber(double fnum, double snum){
    this.fn = fnum;
    this.sn = snum;
}
public double getNumber1(){
    return fn;
}
public double getNumber2(){
    return sn;
}
public void setOper(char oper){
    this.op = oper;
}
public char getOper(){
    return op;
}
public void getAnswer(){
    double ans;
    switch (getOper()){
        case 'a': {
            ans = add(getNumber1(), getNumber2());
            ansOutput(ans);
            break;
        }case 'b': {
            ans = sub (getNumber1(), getNumber2());
            ansOutput(ans);
            break;
        }case 'c': {
            ans = mul (getNumber1(), getNumber2());
            ansOutput(ans);
            break;
        }case 'd': {
            ans = div (getNumber1(), getNumber2());
            ansOutput(ans);
            break;
        }default:
            System.out.println("--------------------------");
            System.out.println("Invalid choice of operator");
            System.out.println("--------------------------");
        }
    }
    public static double add(double x,double y){
        return x + y;
    }
    public static double sub(double x, double y){
        return x - y;
    }
    public static double mul(double x, double y){
        return x * y;
    }
    public static double div(double x, double y){
        return x / y;
    }

    public static void ansOutput(double x){
        System.out.println("----------- -------");
        System.out.printf("the answer is %.2f\n", x);
        System.out.println("-------------------");
    }
}


推荐答案

重启你的IDE,一切都会好的

Restart your IDE and everything will be fine

这篇关于错误:在类Calculate中找不到主方法,请将main方法定义为:public static void main(String [] args)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆