Loops
Let's test your knowledge on loops in Java with the following problem statements:
Write a Java program to print numbers from 1 to 10 using a for loop.
Create a Java program to print even numbers between 1 and 20 using a for loop.
Write a Java program to calculate the factorial of a given number
n
using a for loop.Develop a Java program to print Fibonacci series up to a given number
limit
using a for loop.Create a Java program to print the multiplication table of a given number
num
using a for loop.Write a Java program to find the sum of all numbers from 1 to 100 using a for loop.
Develop a Java program to check if a given number
num
is prime using a for loop.Create a Java program to find the greatest common divisor (GCD) of two numbers
a
andb
using a for loop.Write a Java program to reverse a given number
num
using a while loop.Develop a Java program to print characters of a given string
str
in reverse order using a for loop.Create a Java program to print the first 10 terms of the series: 1, 4, 7, 10, 13, ... using a for loop.
Write a Java program to find the sum of all even numbers between 1 and 50 using a while loop.
Develop a Java program to print the ASCII values of all uppercase letters using a for loop.
Create a Java program to find the sum of digits of a given number
num
using a while loop.Write a Java program to print the prime numbers between 1 and 100 using a for loop.
Develop a Java program to calculate the power of a given number
base
raised to an exponentexponent
using a for loop.Create a Java program to print the square of numbers from 1 to 10 using a for loop.
Write a Java program to find the factorial of a given number
n
using a while loop.Develop a Java program to print the reverse of a given string
str
using a for loop.Create a Java program to find the sum of all odd numbers between 1 and 50 using a while loop.
Write a Java program to prompt the user to enter a positive integer
num
and keep prompting until a positive integer is entered.Create a Java program to roll a six-sided die repeatedly until the user chooses to stop. After each roll, ask the user if they want to roll again.
Develop a Java program to calculate the sum of digits of a given number
num
using a do-while loop.Write a Java program to keep prompting the user to enter a password until the correct password "password123" is entered.
Create a Java program to generate random numbers between 1 and 100 until a number greater than 90 is generated.
Develop a Java program to prompt the user to guess a secret number between 1 and 100. Keep prompting until the correct number is guessed.
Write a Java program to print the first 10 terms of the series: 1, 3, 5, 7, 9, ... using a do-while loop.
Create a Java program to prompt the user to enter an integer
num
and keep prompting until an even number is entered.Develop a Java program to prompt the user to enter a number between 1 and 10. Keep prompting until a valid number is entered.
Write a Java program to calculate the factorial of a given number
n
using a do-while loop.Create a Java program to calculate the average of numbers entered by the user until a negative number is entered.
Develop a Java program to prompt the user to enter a sequence of numbers. Continue reading numbers until the sum of all entered numbers exceeds 100.
Write a Java program to prompt the user to enter a password. Continue prompting until the correct password "abc123" is entered or until three attempts are made.
Create a Java program to print the numbers from 1 to 10 in reverse order using a do-while loop.
Develop a Java program to repeatedly prompt the user to enter a string until a string containing the word "exit" is entered.
These problems cover a variety of scenarios where you'll need to utilize different types of loops in Java to solve different types of problems.
Last updated