Print Cube Numbers Series in Java

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

Here’s a Java program to print a series of cube numbers up to a given number:

package com.javacodepoint.series;

public class CubeNumbersSeries {
	
	public static void printCubeSeries(int limit) {
		System.out.print("Cube Numbers Series: ");
		for (int i = 1; i <= limit; i++) {
			int cube = i * i * i;
			System.out.print(cube + " ");
		}
		System.out.println();
	}

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

OUTPUT:

Cube Numbers Series: 1 8 27 64 125

Explanation:

In this program, we have a method printCubeSeries that takes an integer limit as input and prints the cube numbers from 1 up to the given limit. The method uses a for loop to iterate through the numbers from 1 to the limit, and for each number, it calculates its cube and then prints it.

See also: Square Numbers Series

Java logical programs list


Java Basic Programs

Java String Programs

Java Programs based on the Collection Framework

Leave a Reply

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