viewing paste Calculate BMI | Java

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import java.util.Scanner;
 
public class   CalculateBMI{
   
   public static void main(String[] args){
      
        //Formula BMI (kg/m2) = weight (kg) / height2 (m2)
        Scanner input = new Scanner(System.in); //Scanner to make input work
        System.out.print("Please input your weight in kg: "); //just a message
        
        double weight = input.nextDouble(); //Get weight
        
        System.out.print("Please input your height in meter: "); //just a message 
        
        double height = input.nextDouble(); //Get height
        
        double output = (weight / (height * height)); //Calculate the result, even though I would probably do it directly within the System.out.println() rather than before, but for clarities sake.
        
        System.out.println(output);
 
    }
}
Viewed 1288 times, submitted by Streusel.