gpt4 book ai didi

java - 计算数组的最大高度

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

<分区>

我正在计算应用程序中插入的 max 高度,它给我一个 ArrayIndexOutOfBound 错误,插入值的时间与长度相同包含 0 索引的数组,但我仍然遇到此错误。

int nrPersons = 3;
double[] height = new double[nrPersons];
double maxHeig = 0;

for (int i = 0; i <= nrPersons; i++) {
Scanner in = new Scanner(System.in);
in.useLocale(Locale.US);

System.out.println("Insert Height");

height[i] = in.nextDouble();

if (height[i]> maxHeig)
maxHeig = height[i];

}

System.out.println("The max Height is: "+maxHeig);

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