Final Programming Examination
Part I – Conceptual Understanding (20 points)
Instructions: Answer the following questions briefly. (2 points each)
1. What is the main difference between a while loop and a do-while
loop in Java?
2. When is a do-while loop preferred over a while loop? Give one
example scenario.
3. What are the three main components of a for loop?
4. What happens if the condition of a while loop is never false?
5. Write the syntax of a for loop that counts from 10 down to 1.
6. What is an infinite loop? Give one way to avoid it.
7. Can a for loop be used without initialization and increment
statements? Explain briefly.
8. How can a break statement be used inside a loop?
9. What is the difference between continue and break in a loop?
10. What happens if the semicolon (;) is accidentally placed
right after a while condition?
Part II – Tracing (20 points)
Instructions: Write the output of the following programs.
1. (10 points)
int x = 1;
while (x < 5) {
[Link](x + " ");
x++;
}
Output: __________________
2. (10 points)
for (int i = 2; i <= 10; i += 2) {
if (i == 6)
continue;
[Link](i + " ");
}
Output: ____________________
Part III – Code Completion (30 points)
Instructions: Fill in the missing parts of the code.
1. (10 points)
Complete the code to display numbers from 1 to 10 using a while loop.
int i = 1;
__________ (__________) {
[Link](i);
________;
}
2. (10 points)
Write a for loop that prints all odd numbers between 1 and 15.
(Only write the for loop statement and its body)
3. (10 points)
Convert the following for loop into a while loop:
for (int i = 5; i >= 1; i--) {
[Link]("Countdown: " + i);
}
Part IV – Programming Problems (30 points)
Instructions: Write the complete Java program as instructed. Include
class, main method, and proper syntax.
1. (15 points)
Write a Java program using a while loop that will ask the user to enter
numbers repeatedly. The program should stop only when the user
enters 0. Then display the sum of all numbers entered (excluding 0).
Sample Output:
Enter number: 5
Enter number: 8
Enter number: -2
Enter number: 0
The sum is 11
2. (15 points)
Write a Java program using a for loop to display the multiplication table
of a number entered by the user.
Sample Output:
Enter a number: 6
6x1=6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60
Bonus Question (Optional – 10 points)
Write a Java program that prints the first 10 numbers of the Fibonacci
sequence using a for loop.
Upload your answer on below g-drive link.
Filename should be LastnameFirstnameMI
[Link]
usp=sharing
Submission is until October 8, 2025 at 9pm