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

Loop in Java Quespaper - Akshit

Uploaded by

not.scribbler
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Loop in Java Quespaper - Akshit

Uploaded by

not.scribbler
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Subject: Java Programming

Topic: Loops in Java


Time: 1 Hour
Maximum Marks: 50

Section A: Multiple Choice Questions (10 Marks)

Each question carries 1 mark.

1. Which of the following is a valid syntax for a for loop in Java?


a) for (int i = 0; i < 10)
b) for int i = 0; i < 10;
c) for (int i = 0; i < 10; i++)
d) for (int i; i < 10; i++)

2. What is the minimum number of iterations executed by a do-while loop?


a) 0
b) 1
c) 2
d) It depends on the condition

3. Which loop is best suited for iterating over a collection in Java?


a) while
b) do-while
c) for
d) enhanced for

4. In a while loop, if the condition is false initially, how many times will the loop body
execute?
a) 0
b) 1
c) Infinite
d) Undefined

5. What keyword is used to exit a loop prematurely in Java?


a) stop
b) break
c) exit
d) continue

---
Section B: Short Answer Questions (20 Marks)

Each question carries 4 marks.

6. Write the syntax of all three types of loops in Java and explain when to use each.

7. Convert the following for loop into an equivalent while loop:

for (int i = 1; i <= 5; i++) {


System.out.println(i);
}

8. What is the difference between break and continue in loops? Provide an example for
each.

9. Write a do-while loop in Java to print numbers from 1 to 10.

10. Explain the concept of an infinite loop with an example. How can we avoid infinite loops?

---

Section C: Programming Questions (20 Marks)

Each question carries 10 marks.

11. Write a Java program to calculate the sum of the first 10 natural numbers using:

for loop

while loop

12. Write a Java program to find the factorial of a number entered by the user using a
do-while loop.

13. Write a program in Java that takes an integer input from the user and prints all the even
numbers from 1 to that number using a while loop.
14. Write a program in java that takes input a number and checks if it is palindrome.
(Example : 121)

You might also like