# BMI calculator

• 11-29-2012, 08:16 PM
BMI calculator
Hey, I need some help with BMI calculator. I tryed to do something, but it doesn't work at all. Maybe someone you could make me a example for this (have more exercises, but I want to do them myself, just need an exaple :P). It pretty much should look like this:

"Insert your name" -> and insert it on next line
"Insert your length in cm" -> and insert it on next line
"Insert your weight in kg" -> and insert it on next line

Then output will tell:

"Hello, (name)!
With length (length) cm and weight (weight) kg your BMI is ...(I) .
Info:
* underweight is under 18,5;
* normal is 18,5 - 24,9;
* overweight is 25 - 29,9;
* too fat is 30 - 39,9;
* extra fat is over 40"

I = K / (P/100)^2

i = BMI
K = weight
p = length
• 11-29-2012, 09:03 PM
Fubarable
Re: BMI calculator
Quote:

Hey, I need some help with BMI calculator. I tryed to do something, but it doesn't work at all. Maybe someone you could make me a example for this (have more exercises, but I want to do them myself, just need an exaple :P). It pretty much should look like this:

Come on now.

We'll be glad to try to help you with your code, but please don't ask anyone to do this for you or to give you an example. Instead please show us what you've tried, and errors or misbehaviors your code may be causing and let's see if we can help y ou.
• 11-29-2012, 09:37 PM
Re: BMI calculator
Ok...heres what I have:
import java.util.Scanner;

public class Kt_2_1 {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
double n, p, k, i;
n = scanner.nextDouble();
p = scanner.nextDouble();
k = scanner.nextDouble();
i = k / ((p / 100)*(p/100));
System.out.printf("Hello: %n\n", );
System.out.printf("With length: %p, cm and weight: %k, kg your BMI is: %i\n");
System.out.printf("Info: \n");
System.out.printf("* underweight is 18,5;: \n");
System.out.printf("* normal is 18.5-24,9;: \n");
System.out.printf("* overweight is 25-29,9;: \n");
System.out.printf("* too fat is 30-39,9;: \n");
System.out.printf("* extra fat is over 40;: \n");

}
}
• 11-29-2012, 10:00 PM
musclecode
Re: BMI calculator
I don't know how to use printf, but after modification looks right. And you can't use double type with name. It's String

import java.util.Scanner;

public class Kt_2_1 {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
double p, k, i;
String n;
n = scanner.nextLine();
p = scanner.nextDouble();
k = scanner.nextDouble();
scanner.close();
i = k / ((p / 100)*(p/100));
System.out.println("Hello: " +n );
System.out.println("With length: " + p + " cm and weight: " +k+" kg your BMI is: " +i);
System.out.println("Info: \n");
System.out.println("* underweight is 18,5;: \n");
System.out.println("* normal is 18.5-24,9;: \n");
System.out.println("* overweight is 25-29,9;: \n");
System.out.println("* too fat is 30-39,9;: \n");
System.out.println("* extra fat is over 40;: \n");

}
}
• 11-29-2012, 10:08 PM