# Thread: BMI practice code

1. ## BMI practice code

Hi, I have written a code to calculate someone's bmi. But at the end of our course, we got the solution and there was a part that I did not understand. Namely why the /100.0 is written after "double length = keyboard.nextInt()"

Java Code:
```import java.util.*;

public class MyBmi {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

System.out.print("Enter your name: ");
String name = keyboard.nextLine();

System.out.print("Enter your length in cm: ");
double length = keyboard.nextInt() /100.0 ;         // why is this /100.0 ??

System.out.print("Enter your weight in kg: ");
int weight = keyboard.nextInt()  ;

double bodyMassIndex = weight / ( length * length);

System.out.printf("Hello %s, your BMI is %.1f. ", name, bodyMassIndex);
if ( bodyMassIndex < 18.5) {
System.out.println("You have underweight.");
} else if (bodyMassIndex >= 18.5 && bodyMassIndex < 25) {
System.out.println("You have a normal weight.");
} else if (bodyMassIndex >= 25 && bodyMassIndex < 30) {
System.out.println("You have overweight.");
} else if (bodyMassIndex >= 30 && bodyMassIndex < 40) {
System.out.println("You are obese.");
}
System.out.println();  //blank line
System.out.println( "Hi " +name  + "." + " It's important to stay healthy, remember that!");  // + sign to concat !!!
}
}```

Can anyone help me with this. I want to say, I'm a complete beginner. So I hope I understand the answer

2. ## Re: BMI practice code

That formula wants the length measured in metres and your program wants the length input in centimetres.

kind regards,

Jos

3. ## Re: BMI practice code

got it, thanks JosAH, you're a lifesaver

4. ## Re: BMI practice code

Originally Posted by Evana
you're a lifesaver
I know ...

kind regards,

Jos

5. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: BMI practice code

Yeah. Give the man a cheroot. :)

Regards,
Jim

6. ## Re: BMI practice code

Originally Posted by jim829
Yeah. Give the man a cheroot. :)
A cheroot? Yuck, no thanks; I only smoke Van Nelle Zware Shag or an occasional Brandaris ...

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•