gpt4 book ai didi

java - (JAVA)BMI计算,突然终止

转载 作者:行者123 更新时间:2023-11-30 06:30:36 26 4
gpt4 key购买 nike

我需要创建一个 BMI 程序来判断您是否超重、体重不足、正常或肥胖。我没有错误,但它启动并自动终止。什么都没发生。调试了一下,得到了这个。

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code     = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [util.c:840]

这是代码。

package set2scanner;

import java.util.Scanner;

public class ten {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] size = {"Under", "Normal", "Over", "Obese"};

for (int x = 0; x > 3; x++) {
System.out.println("Please enter your height!");
float h = input.nextInt();
System.out.println("Please enter your weight!");
float w = input.nextInt();
float bmi = doMath(h, w);

if (bmi < 18.5) {
System.out.println("Your BMI is: " + doMath(h, w) + ". You are " + size[0]);
} else if (bmi >= 18.5 && bmi < 25.0) {
System.out.println("Your BMI is: " + doMath(h, w) + ". You are " + size[1]);
} else if (bmi >= 25.0 && bmi < 30.0) {
System.out.println("Your BMI is: " + doMath(h, w) + ". You are " + size[2]);
} else if (bmi >= 30.0) {
System.out.println("Your BMI is: " + doMath(h, w) + ". You are " + size[3]);
}
}
input.close();
}

static float doMath(float weight, float height) {
return weight / (height * height);
}

}

最佳答案

在 for 循环中,有 int x = 0; x > 3; x++。由于您将 x 初始化为 0,因此条件 x > 3 将始终为 false,因此循环将永远不会执行,程序将在您启动时终止

关于java - (JAVA)BMI计算,突然终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46229406/

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