# Java Program to Print the Series 4 16 36 64 100 …N

In the previous article we have discussed about Java Program to Display the Series 1 9 25 49 81 121 …N

In this article we are going to see how to print the series 4 16 36 64 100 …N by using Java programming language. You can also find 4,16,36,64,100 Nth Term. 4 16 36 64 100 sequence, 4 16 36 sequence and 4 16 36 pattern. We include N in java, 1 9 25 49 Series In Java, 0 7 26 Series In Java, 0 7 26 63 Series In Java.

## Java Program to Print the Series 4 16 36 64 100 …N

On observing the pattern carefully, you can see it is in the format of i^2 where ‘i‘ values starts from 2 and goes on incremented by 2.

Example:

Suppose value of N=4
Then
i=2 so 2^2=4
i=4 so 4^4=16
i=6 so 6^6=36
i=8 so 8^8=64
So the final series is like 4 16 36 64

Let’s see different ways to to print the series 4, 16, 36, 64, 100 …N

### Method-1: Java Program to Print the Series 4 16 36 64 100 …N By Using For Loop

Approach:

• Create Scanner class object.
• Declare an integer variable say ‘n’, which holds the Nth term of the series.
• Prompt the user to enter a number as value of ‘n’.
• Use a for loop from i=2 to i<=2*n, where the loop is incremented by 2
• Inside the loop we will find the value of integer variable result = i*i
• Print the result in the series.

Program:

import java.util.*;
public class Main
{
public static void main(String [] args)
{
//creating object of Scanner class
Scanner s = new Scanner(System.in);
//Taking input of number of elements in the series
System.out.println("Enter the Nth term “N” ");
int n = s.nextInt();
//for loop to print the series
for (int i = 2; i <=2*n; i+=2)
{
int result =(i*i);
System.out.print(result+" ");
}
}
}

Output:

Enter the Nth term “N”
5
4 16 36 64 100

### Method-2: Java Program to Print the Series 4 16 36 64 100 …N By Using While Loop

Approach:

• Create Scanner class object.
• Declare an integer variable say ‘n’, which holds the Nth term of the series.
• Prompt the user to enter a number as value of ‘n’.
• Declare and initialize an integer variable i=2
• Continue a while loop till i<=2*n, where the loop is incremented by 2
• Inside the loop we will find the value of integer variable result = i*i
• Print the result in the series.

Program:

import java.util.*;
public class Main
{
public static void main(String [] args)
{
//creating object of Scanner class
Scanner s = new Scanner(System.in);
//Taking input of number of elements in the series
System.out.println("Enter the Nth term “N” ");
int n = s.nextInt();
int i=2;
while(i<=2*n)
{
int result =i*i;
System.out.print(result+" ");
i+=2;
}
}
}

Output:

Enter the Nth term “N”
6
4 16 36 64 100 144

### Method-3: Java Program to Print the Series 4 16 36 64 100 …N By Using User Defined Method

Approach:

• Create Scanner class object.
• Declare an integer variable say ‘n’, which holds the Nth term of the series.
• Prompt the user to enter a number as value of ‘n’.
• Call a user defined method say printSeries() by passing n as parameter.
• Inside method use a for loop from i=2 to i<=2*n, where the loop is incremented by 2.
• Inside the loop we will find the value of integer variable result = i*i
• Print the result in the series.

Program:

import java.util.*;
public class Main
{
public static void main(String[] args)
{
// creating object of scanner class
Scanner s = new Scanner(System.in);
//Taking input of number of elements in the series
System.out.println("Enter the value of Nth term 'N' ");
int n = s.nextInt();
// calling printSeries method to print the series
printSeries(n);
}
//user defined method printSeries() to print the series
public static void printSeries(int n)
{
//for loop to print the series
for (int i = 2; i <=2*n; i+=2)
{
int result =(i*i);
System.out.print(result+" ");
}
}
}

Output:

Enter the value of Nth term 'N'
5
4 16 36 64 100

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts. On basis of the above programming language you can practice 36+16, 16 *36, 16/36*100, 16 By 36.

Related Java Programs: