Program to generates and find thw sum of the series, 1+4+9+16+…………..

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

System.out.println("Enter a number::");
num=obj.readLine();
n=Integer.parseInt(num);
for(int i=1;i<=n;i++)
{
sum=sum+ i*i;
System.out.print(i*i+" ");
}
System.out.println("Sum of the series is="+sum+".");
}
}
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