Print Even Numbers Series in Java

In this post, you will learn how to print the even numbers series using a Java program. Here, we will print a series of even numbers up to a given number or for a specific number of terms.

Let’s see the Java program for it below:

package com.javacodepoint.series;

public class EvenNumbersSeries {

	public static void printEvenSeries(int limit) {
		System.out.print("Even Numbers Series: ");
		for (int i = 2; i <= limit; i += 2) {
			System.out.print(i + " ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		int limit = 10;
		printEvenSeries(limit);
	}
}

OUTPUT:

Even Numbers Series: 2 4 6 8 10

Explanation:

In this program, we have a method printEvenSeries that takes an integer limit as input and prints all even numbers from 2 up to the given limit. The method uses a for loop with an increment of 2 (since even numbers are divisible by 2) to generate and print the even numbers.

See also: Java Program to Print Series 1,2,5,10,17

Java logical programs list


Java Basic Programs

Java Programs based on the Collection Framework

Leave a Reply

Your email address will not be published. Required fields are marked *