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

A Program to Display Even Numbers in a Range in Java
A Program to Display Even Numbers in a Range in Java

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);
		}
	}
}
Printing Even Numbers in the Given Range
Printing Even Numbers in the Given Range

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);
		}
	}
}
Odd Numbers in the Given Range in Java
Odd Numbers in the Given Range in Java

Further Reading

Java Practice Exercise

programmingempire

Princites