Write a java program to print even numbers from 1 to 100 using for loop
Answers
Explanation:
section, we will create a Java program to display even numbers from 1 to 100. To learn the Java even number program, you must have the basic knowledge of Java for loop and if statement.
We can use different ways to display even numbers:
Using Java for Loop
Using nested-if Statement
Using while Loop
Using Java for Loop
In the following example, we have declared a variable named number and initialized it with 100 (the limit to print the even number). We have used a for loop that executes up to 100 times and for each iteration of i the if statement checks the number is even or not. After printing each even number, the value if i is increased by 1.
In order to check the number, we have divided the number by 2 if it does not leave any remainder, the number is even and the print statement prints that number.