Unable to submit the solution to a problem

I have written the code to the following
problem

The output I am getting is correct but still it shows wrong answer.I have read FAQs but still no nuccess.Where I am doing wrong.(I am a new user to codechef and joined today only)

Here is my code

    import java.io.*;

class abc
{
	public static void main(String args[])
	{
		try{
					String num;
					BufferedReader in=new BufferedReader(new FileReader("in.txt"));
					BufferedWriter out=new BufferedWriter(new FileWriter("out.txt"));

					while((num=in.readLine())!=null)
					{
						if(Integer.parseInt(num)==42)
							break;
						else
							out.write(num+"\n");
					}
					in.close();
					out.close();
		}catch(Exception e)
		{
			System.out.println("File not found");
		}
	}
}

You missed that program have to read from stdin - FAQ | CodeChef

1 Like

@codernavi18 : Who told you that input will be available in file named “in.txt” and that you have to create a output file and that you can print messages .

You have read your input from Standard Input

i.e write , BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

And write your output to standard output

i.e. write , BufferedWriter out=new BufferedWriter(System.out);

General Tip : You should not print any messages also , you can assume input to match constraints given in the problem and your output should match exactly the format mentioned in problem statement .

@codernavi18 Read the sample solutions, especially, sample solution in Java, to get a feel of how problem solving is done in codechef.