Jacob Kenyon
Jacob Kenyon

Reputation: 21

(JAVA) BMI calc, terminating suddenly

I need to create a BMI program that tells whether you're overweight, underweight, normal or obese. I have no errors, but it starts and automatically terminates. Nothing happens. Debugged and got this.

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]

Here is the code.

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);
    }

}

Upvotes: 1

Views: 61

Answers (1)

Chris Witteveen
Chris Witteveen

Reputation: 495

In your for loop you have int x = 0; x > 3; x++. Since you initialize x on 0, the condition x > 3 will always be false, thus the loop will never be executed and the program will terminate when you start it

Upvotes: 1

Related Questions