简体   繁体   English

我的代码遇到了运行时错误,有人可以帮我找出我哪里错了

[英]i got Runtime Error for my code ,can anyone help me to find out where i am wrong

i am getting Runtime Error - NZEC for my code given below.I am not been able to understand why.Can anyone help me out with that. 我在下面给出的代码中遇到运行时错误-NZEC。我无法理解为什么。有人可以帮我解决这个问题。

problem statement: Various signal towers are present in a city.Towers are aligned in a straight horizontal line(from left to right) and each tower transmits a signal in the right to left direction.Tower A shall block the signal of Tower B if Tower A is present to the left of Tower B and Tower A is taller than Tower B. So,the range of a signal of a given tower can be defined as : 问题陈述:城市中存在各种信号塔,塔沿水平线排列(从左到右),并且每个塔都从右向左传输信号。如果塔是A,则塔A将阻止塔B的信号A位于塔B的左侧,塔A比塔B高。因此,给定塔的信号范围可以定义为:

{(the number of contiguous towers just to the left of the given tower whose height is less than or equal to the height of the given tower) + 1}. {(位于给定塔的左侧,其高度小于或等于给定塔的高度的连续塔的数量)+1}。

You need to find the range of each tower. 您需要找到每个塔的范围。

INPUT INPUT

First line contains an integer T specifying the number of test cases. 第一行包含一个整数T,它指定测试用例的数量。

Second line contains an integer n specifying the number of towers. 第二行包含一个整数n,用于指定塔数。

Third line contains n space separated integers(H[i]) denoting the height of each tower. 第三行包含n个以空格分隔的整数(H [i]),表示每个塔的高度。

OUTPUT OUTPUT

Print the range of each tower (separated by a space). 打印每个塔的范围(以空格分隔)。

Constraints 约束

1 <= T <= 10 1 <= T <= 10

2 <= n <= 10^6 2 <= n <= 10 ^ 6

1 <= H[i] <= 10^8 1 <= H [i] <= 10 ^ 8

my code 我的密码

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



class TestClass {
    public static void main(String args[] ) throws Exception {
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       int t=Integer.parseInt(br.readLine());
        Scanner sc = new Scanner(System.in);
       while(t!=0)
       {
           int n=Integer.parseInt(br.readLine());

           int arr[]=new int[n-1];
           int atest[]=new int[n-1];

           for (int i=0;i<n;i++)
           {
               arr[i]=sc.nextInt();
           }

           for(int j=n-1;j>=0;j--)
           {
               int count=0;
              int temp=j-1;
               while(arr[j]>=arr[temp])
               {

                   count++;
                   temp--;  

               }
               atest[j]=count;
           }

           for(int k=0;k<n;k++)
           {
              System.out.println(atest[k]+1);  
           }

           t--;

       }



    }
}
       int arr[]=new int[n-1];
       int atest[]=new int[n-1];

       for (int i=0;i<n;i++)
       {
           arr[i]=sc.nextInt();
       }

because array length is n-1 (arr.length = n-1) 因为数组长度是n-1(arr.length = n-1)

that is why you're getting ArrayIndexOutOfBoundsException. 这就是为什么您得到ArrayIndexOutOfBoundsException的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在以下 Java 代码中遇到错误,任何人都可以帮助我 - I am facing an error in the following java code can anyone help me out 谁能告诉我在这种情况下我哪里错了? - Can anyone tell me where i am wrong in this condition? 任何人都可以帮助我了解在 Android 中使用 AsyncTask 时出现错误代码 400 - Can anyone help me about I am getting error code 400 while working with AsyncTask in Android 我从Firebase获取数据并在TextView中显示它但我收到了一些错误。 任何人都可以检查我的代码并建议我 - I am getting data from Firebase and showing it in the TextView but I am getting some error. Can anyone please check out my code and suggest me 这是简单的抽象演示代码,我无法创建suresh类的对象,有人可以帮助我解决这里发生的问题 - This is simple Abstraction demo code where i am not able to create a object of suresh class can someone help me out what is going wrong here 我得到了主要路径问题的错误答案 谁能帮我找到问题? - I am getting wrong answer for prime path problem can anyone help me in finding the issue? 来自孩子 class 的测试用例没有运行,遇到错误谁能指导我哪里出错了 - Test cases from child class is not running, facing error can anyone please guide me where I am going wrong 有没有人可以帮助我解决这个运行时错误? - Is there anyone that can help me with this Runtime error? 任何人都可以看到我错在哪里,我的代码应该返回 true 但它返回 false 它不应该返回 - Can anyone see where i am wrong , My code should return true but its returning false which it should not be returning 我无法从JSON数组中获取图像字节,有人可以帮助我吗? - I am unable to get image bytes from my JSON array, can anyone help me?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM