0% found this document useful (0 votes)
13 views3 pages

Lab 6 - While and Do While

Uploaded by

jbb12191
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)
13 views3 pages

Lab 6 - While and Do While

Uploaded by

jbb12191
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/ 3

Lab 6_ while Loop

1. (using while loop) Write a Java program to print the even numbers from 0 to n.
Print each number per line.

2. (using a while loop) Write a Java program to read 10 players' ages and print
how many of them are less than 20 years old.

3. (using while loop) Write a Java program that reads a number and prints the
timetable of that number.

4. (using a while loop) Write a Java program that reads the marks of students in a
course until the user enters -1 Then the program prints the total and the average
of the marks. The running of the program is shown below

Test Data:
Enter Course Name: Programming in Java
Welcome to the grade book for Programming in Java!
Enter grade or -1 to quit: 90
Enter grade or -1 to quit: 60
Enter grade or -1 to quit: 50
Enter grade or -1 to quit: 40
Enter grade or -1 to quit: 80
Enter grade or -1 to quit: 90
Enter grade or -1 to quit: 80
Enter grade or -1 to quit: -1

Expected output:
Total of the 7 grades entered is 490
Class Average is 70.0
Lab 5_ do while Loop
1. (using do while) Write a program to print the following

$$$$$
$$$$$
$$$$$
$$$$$
$$$$$

2. (using do while) Write a program in Java to display the cube of the number up
to given an integer for example:

Test Data:
Input number of terms : 5
Expected output:
Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
Number is : 5 and cube of the 5 is :125

3. (using do while) Write a Java program to calculate the factorial of a given


number.
N! = N * (N - 1) ... * 3 * 2 * 1
If we say N = 5, Then the factorial of 5 is represented as 5!
And, 5! = 5 * 4 * 3 * 2 * 1 = 120
Test Data:
Input the number : 5
Expected output:
The Factorial of 5 is: 120

You might also like