Nitanshu
Nitanshu

Reputation: 846

Why am I getting could not find or load main class error?

I am trying to run this piece of code

import java.io.*;

class Palindrome{
    public static void main(String args[]) throws IOException
    {
        BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
        int n, temp, rev=0;
        System.out.print("Input a number--> ");
        n = Integer.parseInt(obj.readLine());
        temp = n;
        while(temp != 0){
            rev = rev*10 + temp%10;
            temp /= 10;
        }
        if( n == temp)
            System.out.println(n + " is a palindrome.");
          else
             System.out.println(n + " is not a palindrome.");
    }
}

I name the file palindrome.java. The file compiles easily using without showing any error

javac palindrome.java

but when I run

java Palindrome.class

It shows

Error: Could not find or load main class Palindrome.class

The result of ls in my working directory is:

Palindrome.class  palindrome.java

Upvotes: 0

Views: 197

Answers (1)

ELITE
ELITE

Reputation: 5940

run using

java Palindrome

and not

java Palindrome.class

Upvotes: 4

Related Questions