0% found this document useful (0 votes)
3 views2 pages

Java Loop Practice Worksheet

The Java Loop Practice Worksheet consists of 20 problems focusing on various types of loops including basic, conditional, nested, and pattern-based loops. It is divided into three parts: basic loop problems, pattern printing using nested loops, and string and array loops. Sample solutions are provided for some questions to assist learners in coding their answers.
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 views2 pages

Java Loop Practice Worksheet

The Java Loop Practice Worksheet consists of 20 problems focusing on various types of loops including basic, conditional, nested, and pattern-based loops. It is divided into three parts: basic loop problems, pattern printing using nested loops, and string and array loops. Sample solutions are provided for some questions to assist learners in coding their answers.
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

Java Loop Practice Worksheet

This worksheet contains 20 loop-based Java problems covering basic, conditional, nested,
and pattern-based loops. Try to solve each problem by writing Java code. Solutions are
provided after the questions.

Part A: Basic Loop Problems


1. 1. Print numbers from 1 to 50.
2. 2. Print even numbers from 1 to 100.
3. 3. Print the sum of the first 20 natural numbers.
4. 4. Print all numbers between 1 and 100 that are divisible by both 3 and 5.
5. 5. Print the multiplication table of a given number (e.g., 7).
6. 6. Count how many numbers between 1 and 100 are divisible by 9.
7. 7. Reverse the digits of a given number.
8. 8. Find the factorial of a given number.
9. 9. Check if a number is a prime number.
10. 10. Print the first 10 Fibonacci numbers.

Part B: Pattern Printing (Nested Loops)


11. 11. Print the following pattern:
*
**
***
12. 12. Print a square of stars of size 5x5.
13. 13. Print a right-angled triangle of numbers (1 to n).
14. 14. Print a pyramid pattern of stars.
15. 15. Print a pattern of alternating 1s and 0s in rows.

Part C: String and Array Loops


16. 16. Count the number of vowels in a string.
17. 17. Reverse a string using a loop.
18. 18. Find the largest number in an array.
19. 19. Count how many times a specific element appears in an array.
20. 20. Print all elements of an array in reverse order.
Solutions (Sample Code)
Here's a sample solution for Question 4:

public class DivisibleBy3And5 {


public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
[Link](i);
}
}
}
}

You might also like