Program to generates and find thw sum of the series, 4+12+36+108+……..

import java.io.*;
class test
{ public static void main(String[] asd)throws IOException
{
BufferedReader obj= new BufferedReader(new InputStreamReader(System.in));
int n,sum=1,result=0;
String num;

System.out.print("Enter a number:: ");
num=obj.readLine();
n=Integer.parseInt(num);
for(int i=0;i<n;i++)
{   sum=1;
for(int j=0; j<i;j++)
{
sum=sum*3;
}

result+= 4*sum;
System.out.print((4*sum)+" ");
}
System.out.println();
System.out.println("Sum of the series is="+result+".");
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s