Question 1. Use if statements to write a Java program that prints out (outputs)
ID: 3754961 • Letter: Q
Question
Question 1. Use if statements to write a Java program that prints out (outputs) a person's Body Mass Index (BMI) based on the following conditions BMI less than 18.5; output "underweight" BMI less than 25; output "norma" BMI less than 30; output "overweight" BMI greater than or equal to 30; output "obese" Note: Use if-then-else-if, where appropriate. Expected Output: normal Question 2. Modify the program written in Question 1 to do the following BMI less than 30; output "overweight" BMI greater than or equal to 30; output"obese" Note: receive BMI as input (take input using the Scanner class) Note: Use if-then-else, where appropriate Output: The program may operate like this (sample output): Enter BMI: 29 You entered BMI of 29.0 which is overweightExplanation / Answer
Question 1:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter BMI: ");
float number = input.nextFloat();
if (number < 18.5) {
System.out.println("You entered a BMI of"+" "+number+" "+"which is underweight");
}
else if(number >= 18.5 && number<25) {
System.out.println("You entered a BMI of"+" "+number+" "+"which is normal");
}
else if(number >= 25 && number<30) {
System.out.println("You entered a BMI of "+" "+number+" "+"which is Overweight");
}
else if(number >= 30) {
System.out.println("You entered a BMI of"+" "+number+" "+"which is obese");
}
else{
System.out.println("Enter a Valid number.");
}
}
}
Question 2: Just edit below things :
conditions in elif statements to number <30 and >=30.
Output in System.out.print Statements : "Overweight " and "Obese"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.