Results 1 to 3 of 3
  1. #1
    OldSkoolBray is offline Member
    Join Date
    Apr 2014
    Posts
    17
    Rep Power
    0

    Default How to restart the program once an answer has been found?

    Hello i am creating a body mass index calculator and i was wondering how i could make its so that the program resets itself once the BMI has been found....

    My code is below...

    package bmiCalculatorSource;

    import java.util.Scanner;

    public class BMICalculator {
    public static void main(String[] args) {

    final double KilogramsPerPound = 0.453;
    final double MetersPerInch = 0.026;

    Scanner input = new Scanner(System.in);

    System.out.println("Enter weight in pounds: ");
    double weight = input.nextDouble();

    System.out.println("Enter height in inches: ");
    double height = input.nextDouble();

    double weightInKilogram = weight * KilogramsPerPound;
    double heightInMeters = height * MetersPerInch;
    double bmi = weightInKilogram / (heightInMeters * heightInMeters);

    System.out.println("Your Body Mass Index is " + bmi);

    if (bmi < 17.5)
    System.out.println("You Are Anorexia");
    else if (bmi < 19.1)
    System.out.println("You Are Underweight");
    else if (bmi > 19.1 && bmi < 25.8)
    System.out.println("You Are In Normal Range");
    else if (bmi > 25.8 && bmi < 27.3)
    System.out.println("You Are Marginally Overweight");
    else if (bmi > 27.3 && bmi < 32.3)
    System.out.println("You Are Overweight");
    else if (bmi > 32.3 && bmi < 35)
    System.out.println("You Are Obese");
    else if (bmi > 35 && bmi < 40)
    System.out.println("You Are Severely Obese");
    else if (bmi > 40 && bmi < 50)
    System.out.println("You Are Morbidly Obese");
    else if (bmi > 50 && bmi < 60)
    System.out.println("You AreSuper Obese");

    }

    }
    Any help would be much appreciated thanks.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: How to restart the program once an answer has been found?

    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: How to restart the program once an answer has been found?

    "Reset" is such a meaningless term, it is better to just explain things to yourself in plain English (or your native language). Let me rephrase your problem description. You want the application to loop back to the beginning.

    Do you now have an idea of what you might do?

    EDIT: ninja'd of course. You win this one Surfdude.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Help A Program to Restart
    By Icyis in forum New To Java
    Replies: 12
    Last Post: 11-23-2013, 09:30 PM
  2. Replies: 6
    Last Post: 06-19-2013, 05:36 PM
  3. Replies: 7
    Last Post: 10-31-2011, 01:05 AM
  4. How can I restart my jvm and program programmatically?
    By guest_user in forum Advanced Java
    Replies: 7
    Last Post: 08-30-2011, 02:45 PM
  5. Replies: 6
    Last Post: 11-04-2009, 09:41 PM

Posting Permissions

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