Question: Please write 3 Java programs Here is the description for each of the three: 1 . For Loop: Sum of Even Numbers Problem: Write a

Please write 3 Java programs Here is the description for each of the three:
1. For Loop: Sum of Even Numbers
Problem: Write a Java program that calculates the sum of all even numbers between 1 and 100. Use a for loop to iterate through the numbers and accumulate the sum of the even ones.
2. While Loop: Factorial Calculation
Problem: Write a Java program that calculates the factorial of a given number. The number is provided by the user as input. Use a while loop to multiply the numbers from the given number down to 1.
The factorial of 4 is 4*3*2*1. So if the user provided 4 as the input, your program should print:
Factorial of 4 is 24.
3. Do-While Loop: Number Guessing Game
Problem: Write a simple number guessing game where the user has to guess a number between 1 and 10. The program keeps asking for guesses until the user guesses the correct number. Each time the user makes an incorrect guess, the program gives a hint to the user about whether the number they guessed was lower or higher than the correct number. Use a do-while loop to ensure the user is prompted at least once.
You can create a variable in your program with the number the user is supposed to guess.
For example:
int correctNumber =7; // The correct number to guess
a sample output of your program could look like this:
Guess the number (between 1 and 10): 3
Too low, try again.
Guess the number (between 1 and 10): 7
Correct! You guessed the number.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!