gpt4 book ai didi

java.lang.AssertionError : Incorrect result expected [1019. 1690418083019]但发现[755.0]

转载 作者:行者123 更新时间:2023-12-02 01:41:29 25 4
gpt4 key购买 nike

我编写了一段代码来检查数组中的最大值,并在检查所有值后返回最大值。当我运行我的代码时,我不断收到错误。有什么意见吗?

// Initialize maximum to the first value
double maximum = measurements[0];
// Now go through the rest of the array
for (double i = 0; i < measurements.length; i++) {
if (i > maximum) {
maximum = i;
}
}
// At each step, compare the value to our current maximum
// If it's greater, replace maximum
System.out.println(maximum);

java.lang.AssertionError:预期结果不正确 [1019.1690418083019],但发现 [755.0]

最佳答案

请更改

if (i > maximum) {
maximum = i;
}

if (measurements[i] > maximum) {
maximum = measurements[i];
}

实际上,问题在于您将 imaximum 进行比较,而不是 measurements[i]

关于java.lang.AssertionError : Incorrect result expected [1019. 1690418083019]但发现[755.0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54396219/

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