Java中的NZEC运行时错误 [英] NZEC runtime error in Java

查看:62
本文介绍了Java中的NZEC运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码.请检查它在哪里给出运行时异常.我写了一段代码来解决这个问题.

This is my code. Please check it where it is giving runtime exception. I wrote a piece of code to solve this problem.

我不断收到 NZEC(运行时错误),但我找不到代码的哪一部分会导致任何异常,因为它只涉及简单的算术计算(不应该被零除).

I keep getting NZEC(runtime error), but I can't find which part of the code can cause any Exception since it only involves simple arithmetic computation (there should be no chance of divided by zero).

代码的逻辑无关紧要,我只是想知道异常可能隐藏在哪里.

The logic of the code doesn't matter, and I just wonder where the exception could be hiding.

任何人都可以发现任何错误?谢谢.

Any one can spot any bug? Thanks.

import java.io.BufferedReader;
import java.io.File; // headers
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Vector;
import java.math.BigInteger;

public class Mkequal // class
{
    public static void main(String[] args) throws IOException // main class
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System. in));
        Scanner sc = new Scanner(System. in );
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) // while loop
        {
            int sum = 0;
            int n = Integer.parseInt(br.readLine()); //number of elements in array
            int arr[] = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            for (int i = 0; i < n; i++)
                sum += arr[i];
            if (sum % n == 0) //if divisible by n,print n
                System.out.println(n);
            else
                System.out.println(n - 1);

        }
    }
}

推荐答案

您很可能在程序中创建了过多的内存.您必须在 while 循环外创建 array(arr) 并在循环内操作它..

You are most probably creating too many memory in program. you must create array(arr) outside the while loop and manipulate it inside the loop..

这篇关于Java中的NZEC运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆