North South University Department of Electrical and Computer Engineering CSE 215L: Programming Language II Lab Lab
North South University Department of Electrical and Computer Engineering CSE 215L: Programming Language II Lab Lab
Objective:
● To learn to use conditional statements (if, else, switch case)
● To learn the usage of loops (for, while, do-while)
1. Generate a random integer n between 5 and 20 (inclusive). Use for loop to print all integers
from 0 to n separated by a space. To generate a random integer between min and max range:
int n = (int)(min+Math.random()*(max-min+1))
Sample Output:
Random integer: 7
01234567
2. Print the following
12345
1234
123
12
1
3. Write a program which will use while loop to print all the integers between 100 and 150 which
are divisible by 8 in descending order.
Output: 144 136 128 120 112 104
4. Generate a random int between 1990 and 2020. Then print it check if it’s a leap year or not.
Note: A leap year must satisfy any or both of the following conditions:
Divisible by 400
Divisible by 4 and not divisible by 100
Sample output:
2015: false