Wrong Answer to the first problem

My code in Java For the practice problem http://www.codechef.com/problems/TEST

import java.io.*;
class MainClassUse
{
	public static void main(String args[])throws IOException
	{
		Node start=new Node();
		InputStreamReader isr=new InputStreamReader(System.in);
		BufferedReader buf=new BufferedReader(isr);
		System.out.println("Input:");
		String s=buf.readLine();
		start.number=Integer.parseInt(s);
		Node start1=start;
		while(start.number!=42)
		{
			s=buf.readLine();
			start.link=new Node();
			start=start.link;
			start.number=Integer.parseInt(s);
		}
		while(start1.link!=null)
		{
		System.out.println(start1.number);
		start1=start1.link;
		}
	}
}
class Node
{
	int number;
	Node link;
}

it gives a wrong answer. what is the problem.

Your code is correct logically but you are presenting the answer wrongly.

2 mistakes by you…

  1. Driver class containing main should always be called as Main as this is the only way codechef knows in which class your main is.

  2. Don’t output or print unneccesary comments such as “Please Enter Number” or “Input:” or “The sorted list is” as codechef knows what to enter when.Carefully examine the output format specified…Here you just have to print numbers…

After correcting all this your code got all AC…So try removing them by yourself…

Check this link out…

Hope It helped…

HAPPY CODING :slight_smile:

I’ll correct you, only 2.) is valid…

You can name your class as you wish, but your class cannot be public if name is not Main…

@betlista I tried changing the class name containing public static void main to other then Main at ideone at it gave me RTE saying " Could not find or load main class Main"…

I think rules here are different…Are they???

but this problem is valid only for ideone, not for CodeChef

k…Got now Thanks!!!