Module 3: Loop Programs

Java programs that practice loops (for, while, do-while) and iterative logic.

25 program solutions

Back to Topics

Program Solutions

1

Print 1–100

Print numbers from 1 to 100 using a loop.

Beginner
View Solution
2

Print Even Numbers

Print all even numbers in a given range.

Beginner
View Solution
3

Print Odd Numbers

Print all odd numbers in a given range.

Beginner
View Solution
4

Factorial

Find factorial of a number using a loop.

Beginner
View Solution
5

Reverse a Number

Reverse the digits of a number using a loop.

Beginner
View Solution
6

Sum of Digits

Compute the sum of digits of a number.

Beginner
View Solution
7

Count Digits

Count the number of digits in a given integer.

Beginner
View Solution
8

Armstrong Numbers in Range

Print all Armstrong numbers in a given range.

Intermediate
View Solution
9

Prime Numbers in Range

Print all prime numbers in a given range.

Intermediate
View Solution
10

Fibonacci Series

Print Fibonacci series up to N terms using a loop.

Beginner
View Solution
11

GCD (HCF)

Find the greatest common divisor (HCF) of two numbers using Euclidean algorithm.

Intermediate
View Solution
12

LCM

Find the least common multiple of two numbers using GCD.

Intermediate
View Solution
13

Power of Number

Compute a^b using a loop (similar to earlier power program).

Beginner
View Solution
14

Sum of Series

Compute the sum of the series 1 + 2 + ... + n using a loop.

Beginner
View Solution
15

Number Patterns

Print a simple increasing number triangle pattern.

Beginner
View Solution
16

Star Patterns

Print a simple right-angled triangle star pattern.

Beginner
View Solution
17

Floyd Triangle

Print Floyd’s triangle pattern using consecutive numbers.

Beginner
View Solution
18

Pascal Triangle

Generate Pascal’s triangle using loops and binomial coefficients.

Intermediate
View Solution
19

Multiplication Table

Print the multiplication table of a given number.

Beginner
View Solution
20

Factor Pairs

Print all factor pairs (i, n/i) of a given number.

Intermediate
View Solution
21

Prime Check

Check whether a given number is prime using a loop.

Intermediate
View Solution
22

Composite Check

Check whether a given number is composite.

Intermediate
View Solution
23

Perfect Square Check

Check whether a number is a perfect square using loops.

Beginner
View Solution
24

Harshad Number

Check whether a number is a Harshad (Niven) number (divisible by sum of its digits).

Intermediate
View Solution
25

Duck Number

Check whether a number is a duck number (contains zero, but not at the first position).

Intermediate
View Solution