Program to Create Geometric Sequence in java programming language by using user Input.

Geometric sequence program in java

import java.util.Scanner;
 class GeometricSequence
     public static void main(String args[])
 int n=5;   //limit

int r=2;  //common ratio

 int a=2;   //terms

 int sum=0;  //sum of the series

 Scanner sc=new Scanner(;//take input from user

 System.out.print("Enter a first term:");


 System.out.print("Enter n limit:"); 


System.out.print("Enter r common ratio : ");

 r=sc.nextInt(); for(int i=1;i<=n;i++)


     a=a*r;     //multiply different with terms

Enter a first term:8
 Enter n limit:6
 Enter r common ratio : 2
 8 16 32 64 128 256
 Process completed.   

Leave a Reply