Confused in First Question(TEST)

I am solving the very first question in Easy Section(Problem Code: TEST), I know it is silly but I am unable to solve this question.

NZEC exception (NoSuchElementException)is showing up
and sometimes it shows the main method is missing

the code is here:
/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{

    Scanner sc = new Scanner(System.in);
    int num;
        while(true){
               num = sc.nextInt();
               if(num!=42){
                  System.out.println(num);
               }
               else{
                  break;
               }
            
        }
        sc.close();
}

}

Your code seems to work, I just tried
https://www.codechef.com/viewsolution/25982686

It is not working here.

Here? I submitted the code to the problem right here and it accepted. See the link I attached. In the code you pasted above, the * is missing in first two lines but I assume its because of the forum post formatting.

Actually, it worked but in Non-IDE Mode but it in IDE Mode it is not working.

In the IDE, you have to provide custom input to test your code. If you wish to submit from the IDE, select PRACTICE and TEST in the fields about the coding area, and then click SUBMIT at the right bottom.
It is best advised to debug the code offline and then submit in the non-ide mode.

1 Like