×

[closed] Compilation error

 0 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(;;) { 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? asked 09 May '12, 01:00 1●1●1●1 accept rate: 0% 3★kcahdog 10.0k●28●54●129

The question has been closed for the following reason "The question is answered, right answer was accepted" by kcahdog 26 Jan '17, 22:12

 1 Your class is not public. Please read the codechef submission guidelines here: https://discuss.codechef.com/questions/60612/how-to-submit-java-code answered 26 Jan '17, 21:42 4★mb1994 11●4 accept rate: 0%
 0 On CodeChef your class cannot be public, use default: class life { ... }  answered 09 May '12, 08:24 16.9k●49●115●225 accept rate: 11%
 0 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 :) 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 :) answered 24 Jan '17, 15:53 865●2●14 accept rate: 10%

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×5

question asked: 09 May '12, 01:00

question was seen: 1,236 times

last updated: 12 Jul '17, 11:16