Saturday 25 April 2020

DISPLAYING INTEGERS IN NON-DECREASING ORDER USING JAVA LANGUAGE

Q-37- Write a java program that prompts the user to enter three integers and display the integers in non-decreasing order. 

INPUT :
import java.util.Scanner;

public class NCM {

public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);
int a ,b ,c;
System.out.println("Enter Three Integers :");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
int Max=Math.max(a,Math.max(b,c));
int Min=Math.min(a,Math.min(b,c));
int Median=a+b+c-(Max+Min);
System.out.println("Display The Integer In Non-decreasing Order :"+Min+" "+Median+" "+Max);

}


}

OUTPUT :
Enter Three Integers :
2 4 3

Display The Integer In Non-decreasing Order :2 3 4



FINDING BODY MASS INDEX (BMI) USING JAVA LANGUAGE

Q-36- The body mass index (BMI) is commonly used by health and nutrition professionals to estimate human body fat in populations. It is computed by taking the individual's weight (mass) in kilograms and dividing it by the square of their height in meters. i.e.  

                                        𝑀𝑒𝑡𝑟𝑖𝑐:𝐵𝑀𝐼 =𝑊𝑒𝑖𝑔ℎ𝑡 (𝑘𝑔) /(𝐻𝑒𝑖𝑔ℎ𝑡(𝑚))2

   Write a java program by using some if statements to show the category for a given BMI. 

                                                      BMI                            Category                                                         
                                              less than 18.5                underweight                                                                                                                                                    18.5 to 24.9                 normal weight                                                                                                                                                   25.0 to 29.9                   overweight                                                                                                                                                      30.0 or more                       obese

INPUT :
import java.util.Scanner;

public class NCM {

public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);
double weight ,height;
System.out.println("Enter The Weight In Kilogram :");
weight=sc.nextDouble();
System.out.println("Enter The Height In Meter :");
height=sc.nextDouble();
double bmi=weight/(height*height);
System.out.println("BMI Is :"+bmi);
if(bmi<18.5)
{
System.out.println("You Are In Underweight.");
}
else if(bmi>=18.5 && bmi<=24.9)
{
System.out.println("You Are In Normal Weight.");
}
else if(bmi>=25 && bmi<=29.9)
{
System.out.println("You Are In Overweight.");
}
else if(bmi>=30)
{
System.out.println("You Are In Obese.");
}

}


}

OUTPUT :
Enter The Weight In Kilogram :
80
Enter The Height In Meter :
1.6
BMI Is :31.249999999999993

You Are In Obese.