Lab 2
Lab 2
1. Write a program which calculates the Body Mass Index (BMI) of the user input
values.
Also typecast the result if needed.
If your BMI is less than 18.5, it falls within the Under Weight range.
If your BMI is 18.5 to 24.9, it falls within the normal or Healthy Weight range.
If your BMI is 25.0 to 29.9, it falls within the Over Weight range.
Formula: weight (kg) / [height (m)]2
weight in kilograms divided by height in meters squared.
Example: Weight = 68 kg, Height = 165 cm (1.65 m)
Source code:
Output:
Output:
3) Given a positive integer, check if the number is prime or not. A prime is a natural number
greater than 1 that has no positive divisors other than 1 and itself. Examples of the first few
prime numbers are {2, 3, 5, …}
Examples :
Input: n = 11
Output: true
Input: n = 15
Output: false
Input: n = 1
Output: false
Source code:
Output:
4)Take a three-digit number from user, separate each digit of the number and sum them
For example: 123
1+2+3= 6
Source code:
Output:
5) Write a Java program to convert minutes into a number of years and days.
Source code:
Output:
Source code:
Output: