How to get rid of getting NZEC error while submitting solution in java?

post your code using “code” html tag or link your code.

(post deleted by author)

1 Like

use this

int t = 0;
if(scanner.hasNextInt()) t=input.nextInt();

2 Likes

when submitting your code, remember the space provided to you. It usually happens when your program uses more stack memory than provided i.e. stack overflow, try submitting your code in c/c++ . it will reduce your space requirements, i also tried this and it is actually affective

i also got NZEC error while submitting solution in java,error is not coming with custom input.
i tried as you said like below
/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.;
import java.util.stream.
;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//Scanner sc = new Scanner(System.in);
try{
String T = br.readLine();
String T2 = br.readLine();
System.out.println(T+" "+T2);
}catch(Exception e){
e.printStackTrace();}
}
}
i get output as
null null
, is this mean no input is provided for non custom run ?
can you please help

1 Like

Yes :slight_smile:

class MAIN{

public static void main(String[] args){
	try{
	MAXSPSUM m=new MAXSPSUM();
	m.read();
	m.assign()		;
	m.sp_sum();
}

catch(Exception e){System.out.println((e));
return ;
}
}}

class MAXSPSUM{
Scanner sc=new Scanner(System.in);
long k,s;
int n;
int p;
long[] a;
long[] prod;
long[] sum;
public void read(){

	n=sc.nextInt()	;
	k=sc.nextLong();
	s=sc.nextLong();
	this.p=(int)Math.pow(2,n);
	prod=new long[p];
	sum=new long[p];
	a=new long[n];
	for(int i=0;i<n;i++)
		a[i]=sc.nextInt();
}	


public void assign(){

	Arrays.fill(sum,0);
	Arrays.fill(prod,0);
	int i,j,l=0,k;
	for(k=0;k<n;k++){
		for(j=0;j<n;j++){
			for(i=k;i<n-j;i++)	{

				sum[l]=sum[l]+a[i];
				prod[l]=prod[l]*a[i];

			}



			l++;
		}	

	}}

public void sp_sum(){	
	int i;
	long prev=0,max=0;
	for(i=0;i<p;i++){

		prod[i]=prime(i);
		prev=(sum[i])*(k-(prod[i])*s);

		if(prev>max)
			max=prev;

	}
	System.out. println(max);
}	

int prime(int i)		{
	int count=0;	
	for(int j=1;j<=prod[i];j++){
		if(prod[i]%j==0&&Isprime(j))
			count++;
	}

	return count;		
}
boolean Isprime(int i){
	int count=0;
	for(int j=1;j<=i;j++){
		if(i%j==0)
			count++;}
	if(count==2)
		return true;
	else return false;


}		

}
What wrong in this code why it is showing nzec error

I found this the hard way… by default… codechef doesn’t give any test inputs. So, i think, we need to click “custon input”, enter our custom input and then run it. Otherwise, we get this NZEC error

using System;

public class Test
{
public static void Main()
{
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
int x = int.Parse(Console.ReadLine());
int count = 0;
bool isEntered = false;
int[] arr = new int[x];
string value = Console.ReadLine();
for (int j = 0; j < x; j++)
{
arr[j] = int.Parse(value.Split(’ ')[j]);
}
for (int j = 0; j < arr.Length; j++)
{
if (arr[j] == 1)
{
if (count == 0)
{
count++;
isEntered = true;
}
else if (count < 6)
{
isEntered = false;
Console.WriteLine(“NO”);
break;
}
else if(count>=6)
{
Console.WriteLine(“YES”);
break;
}

                }
                else if (isEntered == true)
                {
                    count++;
                }
            }

        }
}

}

This code is showing NZEC problem… Coding in C#… Can anyone help me with this

You need to click on the checkbox mentioning “Custom Input”

Provide the inputs, and the program will work.

//This is for Java

1 Like

enter the custom input before compiling to solve this

1 Like

Why is try catch required in java code to get rid of NZEC?
What is cause of this error NZEC?

public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
try{
Scanner sc = new Scanner(System.in);
int test_cases;
int temp = 0;
final int FIX = 10;
int number;
test_cases = sc.nextInt();
while(test_cases>0)
{
number = sc.nextInt();
while(number>0)
{
temp = temp*FIX + number%FIX;
number /= FIX;
}
number = temp;
temp = 0;
System.out.println(number);
}
test_cases --;
}catch(Exception e){
return;
}
}

In this code, if i remove try catch, it gives Nzec error. Why ?

Use try and catch block

I encountered the same error. This error is encountered while the compiler is trying to take input.
Try this condition while taking input:-
if( scanner.hasNext()) {
input = scanner.nextInt();
};

Thanks man!

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */

class sticktri

{

public static void main (String[] args) throws java.lang.Exception

{

    Scanner sc=new Scanner(System.in);

    int n=sc.nextInt();ArrayList<Integer> a=new ArrayList<>();

    for(int i=0;i<n;i++)

    a.add(sc.nextInt()) ;

    Collections.sort(a);

    Collections.reverse(a);

    for(int i=0;i<n-2;i++)

    {

        if(a.get(i+1)+a.get(i+2)>a.get(i))

        {

            System.out.println("YES");

            System.out.print(a.get(i)+" "+a.get(i+1)+" "+a.get(i+2));

            System.exit(0);

        }

    }

    System.out.println("NO");

}

}

works fine on laptop but NZEC here.help.

Thanks it helped me alot

for _ in range(int(input())):
    n=int(input())
    l=set(map(int,input().strip().split()))
    print(len(l))

how to remove NZEC in this?

Input format
1
3
1 2 3

How to get rid of getting NZEC error while submitting solution in java?

/* 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. */
class Codechef
{
public static void main (String[] args)
{

	Scanner scan = new Scanner(System.in);
	int withdraw = scan.nextInt();
	
	int balance = scan.nextInt();
	
	if(withdraw<balance && withdraw % 5 ==0)
	{
        System.out.println(balance-withdraw-0.50);
	}
	else if (withdraw<balance && withdraw % 5 !=0) 
	{
	    System.out.println(balance);
	}
	else
	{
	    System.out.println(balance);
	}
}

}

use below code to get rid from noSuchElementException…

if(sc.hasNextInt()){
int cases = sc.nextInt();
}

2 Likes