gpt4 book ai didi

java - 数组索引越界异常

转载 作者:行者123 更新时间:2023-11-29 09:43:31 25 4
gpt4 key购买 nike

<分区>

一直在环顾四周,看看是否有什么可以帮助我,但我不太了解人们在回答什么,而且我所了解的任何事情似乎都无法解决问题!所以基本上正如标题所说,我得到了一个数组索引越界异常,我不知道为什么。非常感谢任何帮助。

代码:

import javax.swing.*;

public class Array {
public static void main(String[] args) {
double height[] = new double[10];
String heightAsString;
int i, over18 = 0, under16 = 0;

for(i = 1; i <= height.length; i++){
heightAsString = JOptionPane.showInputDialog("Please Enter The Height Of Person " + i);
height[i] = Double.parseDouble(heightAsString);

if(height[i] > 1.8){
over18 += 1;
}

if(height[i] < 1.6){
under16 += 1;
}
}

JOptionPane.showMessageDialog(null,"The Total Number Of People Over 1.8m Is: " + over18 +
"\nThe Total Number Of People Under 1.6m Is: " + under16);
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com