0

I am using an online compiler to run this simple code but its giving a runtime error, "could not find or load class Main" There is no other syntax error. Kindly suggest a solution.

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");
            }
        }
    }
}
Sneha
  • 29
  • 3
  • This should help: https://stackoverflow.com/questions/7485670/error-could-not-find-or-load-main-class. Your program should contain a method `main` with signature `public static void main (String[]...args)` – Yassin Hajaj Apr 05 '21 at 13:12
  • Does this answer your question? [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – Hawkeye5450 Apr 05 '21 at 13:24

1 Answers1

2

The main method should have signature with public access modifier and static reference.

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