Java – error: the main method cannot be found in the class calculate, please define the main method as: public static void main (string [] args)
•
Java
See the English answer > "main method not found" error when starting program? 7
Error: Main method not found in class Calculate,please define the main method as: public static void main(String[] args)
This is the code:
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("-------------------"); } }
Solution
Restart the IDE and everything will be fine
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码