0% found this document useful (0 votes)
3 views1 page

Java Loop Questions and Solutions

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)
3 views1 page

Java Loop Questions and Solutions

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

Loop Questions – Java

1. Write a Java program using a for loop to print all numbers from 1 to 50.

2. Write a Java program using a while loop to find the sum of all even numbers between 1
and 20.

3. Write a Java program using a do-while loop to print the multiplication table of 7.

4. Write a Java program using a for loop to count how many numbers from 1 to 100 are
divisible by 5.

5. Write a Java program using a while loop to reverse a number (Example: 1234 → 4321).

6. Write a Java program using a do-while loop to print numbers until the user enters 0.

7. Find the output:


for(int i = 1; i <= 5; i++) {
[Link](i + " ");
}

8. Find the output:


int i = 10;
while(i >= 7) {
[Link](i);
i--;
}

9. Find the output:


int i = 1, sum = 0;
do {
sum += i;
i++;
} while(i <= 4);
[Link](sum);

10. Find the output:


for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 2; j++) {
[Link](i + "" + j + " ");
}
}

You might also like