0% found this document useful (0 votes)
20 views

Lab 2

The document provides instructions and examples for 6 programming exercises: 1) calculate BMI from user input, 2) generate random numbers between 1-25 and convert to characters, 3) check if a number is prime, 4) separate and sum digits of a 3-digit number, 5) convert minutes to years and days, 6) convert temperature from Fahrenheit to Celsius.

Uploaded by

aleemabdullah96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lab 2

The document provides instructions and examples for 6 programming exercises: 1) calculate BMI from user input, 2) generate random numbers between 1-25 and convert to characters, 3) check if a number is prime, 4) separate and sum digits of a 3-digit number, 5) convert minutes to years and days, 6) convert temperature from Fahrenheit to Celsius.

Uploaded by

aleemabdullah96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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:

2) Write a program that generates numbers randomly between 1 to 25


and convert numbers to their corresponding characters.
Source code:

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:

6) Write a Java program to convert temperature from Fahrenheit to Celsius degree.

Source code:

Output:

You might also like