Module 3: Loop Programs
Java programs that practice loops (for, while, do-while) and iterative logic.
25 program solutions
Program Solutions
Print 1–100
Print numbers from 1 to 100 using a loop.
Print Even Numbers
Print all even numbers in a given range.
Print Odd Numbers
Print all odd numbers in a given range.
Factorial
Find factorial of a number using a loop.
Reverse a Number
Reverse the digits of a number using a loop.
Sum of Digits
Compute the sum of digits of a number.
Count Digits
Count the number of digits in a given integer.
Armstrong Numbers in Range
Print all Armstrong numbers in a given range.
Prime Numbers in Range
Print all prime numbers in a given range.
Fibonacci Series
Print Fibonacci series up to N terms using a loop.
GCD (HCF)
Find the greatest common divisor (HCF) of two numbers using Euclidean algorithm.
LCM
Find the least common multiple of two numbers using GCD.
Power of Number
Compute a^b using a loop (similar to earlier power program).
Sum of Series
Compute the sum of the series 1 + 2 + ... + n using a loop.
Number Patterns
Print a simple increasing number triangle pattern.
Star Patterns
Print a simple right-angled triangle star pattern.
Floyd Triangle
Print Floyd’s triangle pattern using consecutive numbers.
Pascal Triangle
Generate Pascal’s triangle using loops and binomial coefficients.
Multiplication Table
Print the multiplication table of a given number.
Factor Pairs
Print all factor pairs (i, n/i) of a given number.
Prime Check
Check whether a given number is prime using a loop.
Composite Check
Check whether a given number is composite.
Perfect Square Check
Check whether a number is a perfect square using loops.
Harshad Number
Check whether a number is a Harshad (Niven) number (divisible by sum of its digits).
Duck Number
Check whether a number is a duck number (contains zero, but not at the first position).