-3

I'm supposed to design a program in TextPad to calculate BMI. I can't get the program to calculate the bmi using the formula. This is my code.

import java.util.Scanner;

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

     System.out.print("Enter weight in pounds: ");
     double weightInPounds = keyboard.nextDouble();
     System.out.print("Enter height in inches: ");
     double heightInInches = keyboard.nextDouble();


      double bmi =  weightInPounds/(heightInInches * heightInInches) * 703;

      System.out.println("Your body mass index is" + bmi);
    }
  }

The output shows:

Enter weight in pounds: 130

Enter height in inches: 66

Your body mass index

Nothing shows for the bmi when I run the program. I compiled the program and TextPad shows no errors. I don't know what is wrong with my code. Can anyone find the error in the code?

1 Answers1

3

You're misusing printf. You should either use string concatenation:

System.out.println("Your body mass index is" + bmi);

or use a correct format string that uses the BMI you pass:

System.out.printf("Your body mass index is %f", + bmi);
nanofarad
  • 40,330
  • 4
  • 86
  • 117
  • Thanks for the help. I figured it out. TextPad couldn't read my equation for bmi. Once I changed it I got the right output. – user3614356 May 08 '14 at 02:36