Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class BMI {
- public static void main(String[] args) {
- //Getting input
- String response = JOptionPane.showInputDialog(null,
- "Enter your height in inches");
- double height = Double.parseDouble(response);
- response = JOptionPane.showInputDialog(null,
- "Enter your weight in pounds");
- double weight = Double.parseDouble(response);
- //Calculation
- double bodyIndex;
- bodyIndex = (weight * 703) / (height * height);
- //Conditionals
- String result;
- if (bodyIndex < 16) {
- result = "Invalid";
- } else if (bodyIndex >= 16 && bodyIndex < 18.5) {
- result = "underweight";
- } else if (bodyIndex >= 18.5 && bodyIndex < 25) {
- result = "Healthy";
- } else {
- result = "Overweight";
- }
- JOptionPane.showMessageDialog(null,
- String.format("Height: %,.2f in\n" +
- "Weight: %,.2f lbs\n" +
- "BMI: %,.2f\n" +
- "Classification: %s\n", height, weight, bodyIndex, result));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment