COMPILATION ERROR I GET:
Main.java:2: class palin is public, should be declared in a file named palin.java
public class palin
^
1 error
MY CODE : import java.util.*;
public class prime
{
public static boolean prime(long a)
{
int c=0;
for(int i=1;i<=a;i++)
{
if(a%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
public static void main()
{
Scanner sc=new Scanner(System.in);
long n,u,l;
n=sc.nextInt();
if(n>1000000000)
System.exit(0);
for(long l1=1;l1<=n;l1++)
{
l=sc.nextInt();
u=sc.nextInt();
if(u-l>100000)
System.exit(0);
for(long i=l;i<=u;i++)
if(prime(i))
System.out.println(i);
}
}
}
1 Like
hey, solution link for your code, its now giving NZEC
But yeah i removed the compiler error, it was because you file was getting saved on server as palin.java, and your class name was also palin, just changed the class name.
now work on this NZEC
1 Like
Your class name is not " Main ".
For Java in codechef online judge have two options
- public class Main{
public static void main (String[] args) throws java.lang.Exception {
// your code here
} }
- class YourClassName{
public static void main (String[] args) throws java.lang.Exception {
// your code here
} }
Remember " the name of the class has to be “Main” only if the class is public. "
If you use some other class do not declare it public, see my example here.
For more information check codechef sample for java here.
Hope this helps.
1 Like
thanx dracowane and mediocoder…solved my problem
thanx a lot
@betu1123581321
If your problem was solved then select any one(or both) as correct/accepted to mark the question as solved.
@betu1123581321
Under the " thumbs up " and " thumbs down " icon on the left side of an answer, there is a green check button ( or tick mark), click that green icon to mark the corresponding answer as the answer which solved your doubt.