# Java Program to Print the Series 6 11 21 36 56 …N

In the previous article we have discussed about Java Program to Print the Series 1 22 333 4444 55555 … N

In this article we are going to see how to print the series 6 11 21 36 56 …N by using Java programming language.

## Java Program to Print the Series 6 11 21 36 56 …N

On observing the pattern carefully, we can see

1st number starts from 6, Then the next number follows a logic

6
6+5 = 11
11+10 = 21
21+15 = 36
36+20 = 56 and so on.

Example:

 6 11 21 36 56 81 …… N

+5                   +10                 +15                 +20                 +25

Let’s see different ways to print the series 6 11 21 36 56 …N

### Method-1: Java Program to Print the Series 6 11 21 36 56 …N By Using For Loop

Approach:

• Create Scanner class object.
• Declare an integer variable say ‘n’ which holds the number of terms in the series.
• Prompt the user to enter a number as value of n.
• Let declare an integer variable say ‘result’ and initialize it to 6
• Let declare another integer variable say ‘add’ and initialize it to 5
• Use a for loop from i=1 to i<=n-1 where the loop is incremented by 1
• Inside the for loop we will find the value of result=result+add and add=add+5.
• 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 result = 6;
System.out.print(result);
//for loop to print the series
for (int i = 1; i <= n-1; i++)
{
System.out.print(" "+result);
}
}
}

Output:

Enter the Nth term “N”
5
6 11 21 36 56

### Method-2: Java Program to Print the Series 6 11 21 36 56 …N By Using While Loop

Approach:

• Create Scanner class object.
• Declare an integer variable say ‘n’ which holds the number of terms in the series.
• Prompt the user to enter a number as value of n.
• Let declare an integer variable say ‘result’ and initialize it to 6
• Let declare another integer variable say ‘add’ and initialize it to 5
• Declare and initialize an integer variable i=1
• Continue a while loop till i<=n-1, where i is incremented by 1.
• Inside the for loop we will find the value of result=result+add and add=add+5.
• 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 result=6;
System.out.print(result);
int i=1;
while(i<=n-1)
{
System.out.print("  "+result);
i++;
}
}
}

Output:

Enter the Nth term “N”
7
6 11 21 36 56 81 111

### Method-3: Java Program to Print the Series 6 11 21 36 56 …N By Using User Defined Method

Approach:

The same logic as method 1 but this time we are moving the for inside a user-defined method

• Create Scanner class object.
• Declare an integer variable say ‘n’ which holds the number of terms in the series.
• Prompt the user to enter a number as value of n.
• Call a user defined method printSeries() by passing n as parameter.
• Inside method declare an integer variable say ‘result’ and initialize it to 6
• Let declare another integer variable say ‘add’ and initialize it to 5
• Use a for loop from i=1 to i<=n-1 where the loop is incremented by 1
• Inside the for loop we will find the value of result=result+add and add=add+5.
• 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);
}

//printSeries metthod to print the series
public static void printSeries(int n)
{
int result = 6, add = 5;
System.out.print(result);
//for loop to print the series
for (int i = 1; i <=n-1; i++)
{
System.out.print(" "+result);
}
}
}

Output:

Enter the value of Nth term 'N'
9
6 11 21 36 56 81 111 146 186

Are you a job seeker and trying to find simple java programs for Interview? This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview.