Loop in Java Quespaper - Akshit
Loop in Java Quespaper - Akshit
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
---
Section B: Short Answer Questions (20 Marks)
6. Write the syntax of all three types of loops in Java and explain when to use each.
8. What is the difference between break and continue in loops? Provide an example for
each.
10. Explain the concept of an infinite loop with an example. How can we avoid infinite loops?
---
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)