Dustin Nichols

@dtnichol (0)
An Introduction to Java
posted to Learn by ArchieMaclean

I am having trouble getting JAVA files to compile. Below, I have pasted some sample code I got from a website. I get an error message: "error: class Factorial is public, should be declared in a file named Factorial.java"

The name of my file is Factorial.java, so I'm not sure what the problem is. I would appreciate any insight :)

public class Factorial
public static void main(String[] args)
{ final int NUM_FACTS = 100;
for(int i = 0; i < NUM_FACTS; i++)
System.out.println( i + "! is " + factorial(i));

public static int factorial(int n)
{	int result = 1;
	for(int i = 2; i <= n; i++)
		result *= i;
	return result;