Compilation error

import java.io.*;
public class life
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
for(;:wink:
{
System.out.println(ā€œEnter no.ā€);
int a= Integer.parseInt(in.readLine());
if(a!=42)
{
System.out.println(a);
}
else
break;
}
}
}

this code runs in my BLUEJ environment which i use for java, but at code chef its giving a compilation error.
what to do?

On CodeChef your class cannot be public, use default:

class life {
    ...
}

good the receiver after inputting the page SHAREit for PC Download Free (Windows 7/8/8.1) & Mac - SHAREit Download for PC, APK, Android & iPhone Free Therefore the telephone will need to possess nice.

I see your code pal. It is the ā€œLife, Universe and Everythingā€ problem. The reason it is not compiling, is because in Codechef and other Online Programming Platforms, you cannot declare your class public. It is against their rules. So, if you just change it to class life{}, it wonā€™t show a compilation error :slight_smile:

Moreover, another error which I found in your code is printing ā€œEnter a numberā€.
I know that in schools and colleges, we are taught to give the prompt ā€œEnter a numberā€, ā€œEnter the sizeā€, etc to start the BlueJ terminal window. But this is a very wrong practice when it comes to Competitive Programming. You will simply get a WA (wrong answer).

Instead of that, what you can do is print a blank line (Sopln()) just once, in the beginning, when working with BlueJ and thereby, also avoid WA. Understand that this practice of printing a line to start the Terminal Window is only required for Bluej, while almost all other Online & Ofline IDEs donā€™t require this.

If you found this helpful, please mark it as accepted :slight_smile:

Your class is not public. Please read the codechef submission guidelines here:
https://discuss.codechef.com/questions/60612/how-to-submit-java-code

1 Like