1 / 5
Oct 2011

My deepest apologies if this is known, has workarounds, and if I'm blind, but I am having a partial serious issue here.
I have solved a problem in Java and saved it in a file called "factorial3.java". My Java class name is "factorial3". I have compiled and ran this problem in both Ubuntu and Mac OS X, and my programs compiles and works fine in both platforms.

However, when I submit the program to the judge, I get a compilation error, and when I click it, I get the following message:

"Main.java:4 class factorial3 is public, should be declared in a file named factorial3.java.
public class factorial3
^

1 error"

I don't get it since factorial3 is indeed in it's own file called factorial3.java.

  • created

    Oct '11
  • last reply

    Mar '13
  • 4

    replies

  • 843

    views

  • 4

    users

On SPOJ for java :
public class Main { - ok
class Main { - ok
public class CustomName { - [color=#FF0000]wrong![/color]
class CustomName { - ok

19 days later
1 year later

I wonder how to use Java on SPOJ and why the following two files do not work together, please? Below please find pasted compilation info first, then the two files:

Main.java:8: error: cannot find symbol
GradeBook myGradeBook = new GradeBook();
^
symbol: class GradeBook
location: class Main
Main.java:8: error: cannot find symbol
GradeBook myGradeBook = new GradeBook();
^
symbol: class GradeBook
location: class Main
2 errors


import java.util.*;
import java.lang.*;

public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
GradeBook myGradeBook = new GradeBook();

    myGradeBook.displayMessage();

    }

}


import java.util.*;
import java.lang.*;

class GradeBook
{
public void displayMessage()
{
System.out.println( "Wecome to the Gradebook!" );
}
}

Both the classes were public in the book I study: public class GradeBook, public class GradeBookTest. And it works in Eclipse. When I had the two classes (public class Main, class GradeBook) in a common package, it failed, too, here at SPOJ. I would be grateful to learn how to achieve the goal (of the same functionality) here on SPOJ, where two public classes are impossible. I am a novice here. Thank you.

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.