The following program demonstrates how to Display Even Numbers in a Range in Java.
Another example of the usage of the for loop in java is given below. The loop control variable i varies from 23 to 57 and prints all even number in-between.
public class Exercise11
{
public static void main(String[] args) {
for(int i=23;i<=57;i++)
{
if(i%2==0)
System.out.println(i);
}
}
}
Output

Another program to display odd and even numbers in the Range 10 to 20.
public class Exercise11A
{
public static void main(String[] args) {
for(int i=10;i<=20;i++)
{
if(i%2==0)
System.out.println(i);
}
}
}

Similarly, we can do for odd numbers.
public class Exercise11A
{
public static void main(String[] args) {
for(int i=10;i<=20;i++)
{
if(i%2!=0)
System.out.println(i);
}
}
}

Further Reading
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
