(JAVA)BMI计算,突然终止

时间:2017-09-14 23:02:17

标签: java

我需要创建一个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);
    }

}

1 个答案:

答案 0 :(得分:1)

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