Hi, I am using this site to teach myself, I havnt coded anything since uni and even then it was badly and in C++ lol.
When I try submitting the following code for the TEST problem (the 42 one) I get a runtime NZEC error. Two things, what it is, and what am I doing wrong?

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        int data;
        do {
        Scanner input = new Scanner(System.in);
        data = input.nextInt();

        if(data != 42) {
            System.out.println(data);
        }
    } while(data != 42);
}
  • created

    Aug '09
  • last reply

    Sep '09
  • 1

    reply

  • 198

    views

  • 2

    users

1 month later

In each loop, you create a new Scanner on System.in and read the first integer and you will never get to the second input.

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.