Guest User

Untitled

a guest
Apr 16th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class BMICategories {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner one = new Scanner(System.in);
  8.         double height, weight, BMI;
  9.         String BMICat = "";
  10.         //remember these? comments wont do anything to the program
  11.         System.out.print("Your height in m: "); //prints the string "your height in m:"
  12.         height = one.nextDouble();
  13.         //asks the user for input, in this case a rational number eg: 10, 5, 4, 1.1, 5.2, 80.343... and then stores it in a variable called height
  14.         System.out.print("Your weight in kg: ");//prints the string "Your weight in kg:"
  15.         weight = one.nextDouble(); //same as height but instead it stores the value in a variable called weight
  16.         BMI = (weight / (height * height));//calculates the variable called "BMI" by dividing weight by height squared
  17.         System.out.println(); //this will just skip a line when stuff is being printed, like pressing enter on word
  18.         System.out.println("\nYour BMI is " + BMI + " ");
  19.         //skips a line and prints "Your BMI is" plus the value that is returned when BMI is calculated
  20.         if (BMI < 18.5) {//if BMI is less than 18.5 then it assigns "underweight" to the string BMIcat
  21.             BMICat = "underweight";
  22.         }
  23.         if (BMI >= 18.5 && BMI < 24.9) {//same thing but instead it assigns "normal weight" to BMICat
  24.             BMICat = "normal weight";
  25.         }
  26.         if (BMI >= 25.0 && BMI < 29.9) {//same thing etc...
  27.             BMICat = "overweight";
  28.         }
  29.         if (BMI > 30.0) {//etc etc...
  30.             BMICat = "obese";
  31.         }
  32.         System.out.println("BMI Category: " + BMICat + " ");//prints "BMI Category: " plus the string that was assigned to BMICat
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment