# Java Program to Print Series 5 25 125 625 3125…N

In the previous article we have discussed about Java Program to Print Series 4 16 64 256 1024 6144…N

In this article we are going to see how to print the series  5 25 125 625 3125…N by using Java programming language. Observe how to wap to print following series 5 10 15 20 25 30 35 python, Java program to print series 1 12 123, java program to print series 2 5 10 17, java program to print series 1 12 123, java program to print 1 22 333, java program to print 12345 pattern, java program to print 1 2 3 4 5, java program to print pattern 1 23 456.

## Java Program to Print the Series 5 25 125 625 3125…N

On observing the pattern carefully, we can see the series starts from 5 and next element is previous element multiplied with 5.

Example:

Suppose value of N=5
So the series is-
5 25 125 625 3125

Let’s see different ways to print the series  5 25 125 625 3125…N

### Method-1: Java Program to Print Series 5 25 125 625 3125…N By Using For Loop

Approach:

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

Output:

Enter the value of number of terms
5
5 25 125 625 3125

### Method-2: Java Program to Print Series 5 25 125 625 3125…N By Using While Loop

Approach:

• Declare an integer variable say ‘n’ which holds the value of number of terms in the series.
• Create Scanner class object.
• Prompt the user to enter a number as value of n.
• Let declare an integer variable ‘result‘ & initialize it to 5
• Declare and initialize an integer variable i=1
• Continue a while loop till i<n incremented by 1.
• Inside while loop we will increment the result with 5 times of the previous result.
• Print the result in the series.

Program:

import java.util.*;
public class Main
{
public static void main(String [] args)
{
Scanner s = new Scanner(System.in);
//Taking input of number of elements in the series
System.out.println("Enter the value of number of terms ");
int n = s.nextInt();
int result=5;
System.out.print(result);
int i=1;
while(i<n)
{
result *=5;
System.out.print(" "+result);
i++;
}
}
}

Output:

Enter the value of number of terms
5
5 25 125 625 3125

### Method-3: Java Program to Print Series 5 25 125 625 3125…N By Using User Defined Method

Approach:

• Declare an integer variable say ‘n’ which holds the value of number of terms in the series.
• Create Scanner class object.
• 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 declare an integer variable ‘result‘ and initialize it to 5.
• Use a for loop from i =1 to i<n incremented by 1.
• Inside for loop we will increment the result with 5 times of the previous result.
• 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 number of terms ");
int n = s.nextInt();
// calling printSeries method to print the series
printSeries(n);
}
public static void printSeries(int n)
{
int result = 5;
System.out.print(result);
//for loop to print the series
for (int i = 1; i < n; i++)
{
result *=5;
System.out.print(" "+result);
}
}
}

Output:

Enter the value of number of terms
4
5 25 125 625

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Test Yourself:

1. What is the nth term of the sequence 25 125 625 3125?
2. Write the while loop to print the series 5 10 15 100?
3. Write a program to print 51015 50 using for loop?
4. Write a program in python to print the following series 25 20 15 10 5?
5. What is the sum to n terms of the series 1 3 5 3 5 7 5 7 9?
6. Write a java program to print value of x^n. input x=5 input n=3 output 125?
7. Print 1 to 5 11 to 15 and 21 to 25 in a single loop till n
8. java program to print 1 2 3 4 5
9. Geometric progression the first two terms are 125 and 15 and its nth term is 625 then n?
10. Given a string = 123am256cd print 2 output strings one for all the numbers and one for strings?

Related Java Programs: