Program to find the sum of the series, 3+5+9+15+……..

import java.io.*;
class test
{
public static void main(String[] asd)throws IOException
{
BufferedReader obj= new BufferedReader(new InputStreamReader(System.in));
String num;
int n,sum=3, result=0;
System.out.print("Enter the value till you want the sum of the series.");
num=obj.readLine();
n=Integer.parseInt(num);
System.out.println("SERIES IS::");
System.out.print("3 ");
for(int i=0;i<n;i++)
{
sum=sum+ (2*(i+1));
result+=sum;
System.out.print(sum+" ");
}
System.out.println("Sum of the series:: "+(result+3)+".");
}
}
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