Results 1 to 5 of 5
Thread: BMI calculator
- 11-29-2012, 07:16 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
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:
Ask:
"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
-
Re: BMI calculator
- 11-29-2012, 08:37 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
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;
System.out.println("Insert your name:");
n = scanner.nextDouble();
System.out.println("Insert your length in cm:");
p = scanner.nextDouble();
System.out.println("Insert your weight in kg:");
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, 09:00 PM #4
Member
- Join Date
- Aug 2012
- Posts
- 9
- Rep Power
- 0
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;
System.out.print("Insert your name:");
n = scanner.nextLine();
System.out.print("Insert your length in cm:");
p = scanner.nextDouble();
System.out.print("Insert your weight in kg:");
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");
}
}Last edited by musclecode; 11-29-2012 at 09:08 PM.
- 11-29-2012, 09:08 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Need help with + - * / calculator
By Aconitum in forum New To JavaReplies: 26Last Post: 08-04-2012, 07:13 PM -
calculator help
By sirstroud in forum New To JavaReplies: 0Last Post: 04-01-2012, 05:58 AM -
Need help with Calculator
By Joshua4missions in forum New To JavaReplies: 4Last Post: 12-10-2011, 02:44 AM -
calculator
By rithish in forum AWT / SwingReplies: 10Last Post: 04-25-2011, 11:24 PM -
Calculator help.
By madkidd02 in forum New To JavaReplies: 2Last Post: 10-25-2008, 07:42 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks