2 / 2
Feb 2018

Receive this “runtime error (NZEC)” when send code to check. When compiling this code on my computer it works. Please, help.

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

class Main
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Scanner src = new Scanner(System.in);
Main obj = new Main();
int t, i, a;
String input;
int[] intArray;

    t = src.nextInt();
    if (t > 10)
    {
        System.exit(0);
    }
    for (i = 0; i < t; i++)
    {
        input = reader.readLine();
        String[] strArray = input.split(" ");
        intArray = new int[strArray.length];
        for (int k = 0; k < strArray.length; k++)
        {
            intArray[k] = Integer.parseInt(strArray[k]);
        }
        
        for (a = 0; a < 1; a++)
        {
            if (intArray.length == 1)
            {
                continue;
            }
            else if (intArray[a] >= 1 && intArray[a] <= 1000000000000000L && intArray[a + 1] >= 1 &&
                    intArray[a + 1] <= 1000000000000000L && intArray[a + 1] - intArray[a] <= 1000000000000000L &&
                    intArray[a] <= intArray[a + 1])
            {
                obj.prime(intArray[a], intArray[a + 1]);
            }
            else
            {
                System.exit(0);
            }
        }
    }

}

void prime(long m, long n)
{
    long j, k;
    long c;
    if (m == 1)
    {
        m++;
    }
    for (j = m; j <= n; j++)
    {
        c = 0L;
        for (k = 2; k <= j / 2; k++)
        {
            if (j % k == 0L)
            {
                c++;
            }

        }
        if (c == 0L)
        {
            System.out.println(j);
        }
    }	

}
}

  • created

    Feb '18
  • last reply

    Feb '18
  • 1

    reply

  • 906

    views

  • 2

    users

  • 1

    link

I don’t know much about java, but running your code on ideone gives:

Exception in thread “main” java.lang.NullPointerException
at Main.main(Main.java:26)

where line 26 is

String[] strArray = input.split(" ");

Printing “input” shows that it’s null.

Does that help?