You are not logged in. Please login at www.codechef.com to post your questions!

×

[closed] 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(;;)
       {
           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

abhijeetiitkgp's gravatar image

2★abhijeetiitkgp
1111
accept rate: 0%

closed 26 Jan '17, 22:12

kcahdog's gravatar image

3★kcahdog
10.0k2854129

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


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

link

answered 26 Jan '17, 21:42

mb1994's gravatar image

4★mb1994
114
accept rate: 0%

On CodeChef your class cannot be public, use default:

class life {
    ...
}
link

answered 09 May '12, 08:24

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

Answer is hidden as author is suspended. Click here to view.

answered 21 Feb '16, 17:47

poptu67's gravatar image

0★poptu67
(suspended)
accept rate: 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 :)

link

answered 24 Jan '17, 15:53

akashbhalotia's gravatar image

5★akashbhalotia
865214
accept rate: 10%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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