A programme which converts weight from pounds to kilograms and the height from inches to centimeters, 
then it calculates body mass index. 


import java.util.Scanner;

public class BodyMassIndex

    public static void main(String[] args)
        Scanner BMI = new Scanner(System.in);

        double p, k, c, i, bmi;

        Scanner scan = new Scanner (System.in);

        System.out.print("How much do you weigh in pounds? ");
        p = scan.nextDouble();

        System.out.print("How much is your height in inches? ");
        i = scan.nextDouble();

        k = p / 2.2;                                                //calculates kilogrammes from pounds

        c = 2.54 * i;                                               //calculates centimeters from inches

        bmi = k / Math.pow(c/100,2);                                //calculates body mass index from the fomula given. 

        System.out.println("A person with weight "+p+" pounds and height "+i+" inches has Body Mass Index of:"+bmi+"") ;


this is the code i wrote...

but the question asks me to evaluate the BMI as an integer...

if I try to name BMI as int, it gives me an error about precision...
anyone know how to solve this problem???

it's because your other variables are doubles.
this basically means they accept decimal values, but an int doesn't.
so, in 0,03 * 1,25 = ...
you would get: 0 as result, because of just that, your precision levels are different, it's like converting a .png image to a .jpg, less colors possible, ...
just read it as a Double (not double) and use the intValue() method to get the value you're looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.