submission woes with Java

Hello,
So, I wrote the code for the first question (life/universe) in Java in under a minute. It took me over half an hour to get it working during the submission process.

It would be nice if the system provided a decent bit of feedback, e.g.

  1. My first fail was because I didn’t call the class Main (I know now it’s in the FAQ but they could easily parse the file to check for useful common errors)

  2. My second fail was simply ‘runtime error’, which turned out after much scratching to be simply I’d left in my package details at the top of the file.

I think most faults would be easier to find if instead of ‘runtime error’ or ‘wrong answer’ with no means of knowing, the submission system provided (in the case of Java/c#/c++ at least) a stacktrace of any exceptions found.

The other problem is it’s quite hard to write nice code due to the limitations of having to submit bare code (i.e. I wrote a harness to determine times, debug info, etc to wrap around the code but for codechef I have to get rid of it all and put everything in one file). I use this for project euler so I didn’t really lose much code.

There is no rule to call class “Main”, at least none of my classes is called so, important is that your class cannot be public, but DEFAULT (aka package visible):

class MyClass {
    ....
}

It is not possible to print stacktrace, reason is that you can add undesirable information into the stacktrace. Assume, that your code is returning WA. If stacktraces are possible, you can do something like

throw new NullPointerException( "N=" + N );

and you will find out something that you shouldn’t…

For using debug info I’m using this

private static final boolean DEBUG = true;

and later when I’d like to print debug message

if (DEBUG) System.out.println( "DEBUG: ...");

Finally when I need to remove debug message I simply switch DEBUG to false. Feature of java is, when compiler finds not reachable code it removes it, so these ifs are simply removed (and not checked in runtime).

Not the best coding practices.

if there is another simple to use solution I’d like to learn something :wink:

Sorry to be soo random but I keep on getting wronge answer but my code is fine ? please help its for Life, the Universe, and Everything

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Integer[] number = new Integer[5];
for(int i = 0;i<number.length;i++)
{
number[i] = sc.nextInt();
}

for(int count = 0; count < number.length; count++)
{
if(number[count] == 42)
{
break;
}else
{
System.out.println(number[count]);
}
}
}
}

//