【问题标题】:Runtime error : could not find main in java program运行时错误:在 java 程序中找不到 main
【发布时间】:2021-07-01 08:23:39
【问题描述】:

我正在使用在线编译器来运行这个简单的代码,但它给出了运行时错误,“找不到或加载类 Main” 没有其他语法错误。请提出解决方案。

import java.io.*;
class weird
{
    void main ()throws IOException
    {
        BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
        int n;
        System.out.println("Enter a number");
        n=Integer.parseInt(br.readLine());
        if (n>=1 && n<=100);
        {
            if(n%2!=0);
            System.out.println("Weird");
            if(n%2==0);
            {
                if(n<=5&&n>=2)
                System.out.println("Not Weird");
                else if(n<=20&&n>=6)
                System.out.println("Weird");
                else if(n>20)
                System.out.println("Not Weird");
            }
        }
    }
}

【问题讨论】:

标签: java error-handling compiler-errors


【解决方案1】:

主方法应该有公共访问修饰符和静态引用的签名。

import java.io.*;
class weird {
    public static void main (String []args)throws IOException {
        // all your code goes here.
    }
}

【讨论】:

    猜你喜欢
    • 2021-10-24
    • 1970-01-01
    • 2015-04-15
    • 2016-02-01
    • 2014-11-15
    • 1970-01-01
    • 2016-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多