Why do i keep getting error while my program works in my local

Hi i keep getting compile or run time exception, even though my program is working fine in my local, like this below example -

import java.util.ArrayList;
import java.util.Scanner;

public class Fombinatorial {

public static void main(String[] args) {
	// TODO Auto-generated method stub

	Scanner s=new Scanner(System.in);
	int testcases = s.nextInt();
	int M=0;
	int N=0;
	int Q=0;
	ArrayList queueList=new ArrayList<Integer>();
	
	if(testcases > 0){
		int i=0;
		while(testcases > i)
		{
		M=s.nextInt();
		N=s.nextInt();
		Q=s.nextInt();
		i++;
		int f[] = new int[M+1];
		
		if(Q > 0){
			for(int j=0;j<Q;j++)
			{
				queueList.add(s.nextInt());
			}
		}
		
		for(int k=1;k<=M;k++)
		{
			//for(int j=k;j>0;j--){
				if(k==1)
					f[k] = 1;
				else
					f[k] = f[k-1]* GetPower(k);
			//}
			
		}
		int div = 1;
		
		for(int k=0;k<queueList.size();k++)
		{
			div =div*f[(int) queueList.get(k)];
		}
		int output = (f[M]/div) % N;
		System.out.println(output);
		System.out.println(output);
		}
		
	}
	
	
}

private static int GetPower(int k) {
	// TODO Auto-generated method stub
	int pow=1;
	for (int i=0;i<k;i++)
		pow = pow*k;
	
	return pow;
}

}

What is wrong with this program???

Class used on online judge or on codechef is Main. Change your class name to Main. When you submit your code in Java, CodeChef takes your code and puts it in its own java file named Main.java. The Java programming language does not allow file names to have names that are different from the name of the public class in the file. Since your class name is “Approximately” and CodeChef’s file name is “Main”, it throws an exception. If you were programming for fun, you would have the option of either changing the class name to the file name or the file name to the class name. But, since you cannot change CodeChef’s file name, you have to change your class name to Main.

So in short, just change your class name to “Main”(quotes for clarity) and you should be fine.

1 Like

or simply delete public keyword so the class is not public anymore…

@betlista Yeah, even that is the simple solution… :slight_smile:

Anything like this will also work:

class myclass{   // notice absence of public
   // all evaluations
}