#### https://java4school.com/sum-series-part-1

## Series programs part 2

Write a program to print the following series.

0, 4,18,48,100…..n

```
import java.io.*;
class series
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number of ur choice");
int n=Integer.parseInt(br.readLine());
int a=1;
while(a<=n)
{
double b=(int)Math.pow(a,2);
double c=(int)Math.pow(a,3);
double num=(int)c-b;
System.out.print(num+",");
a++;
}
}
}
```

Write a java program to solve the following series

1+(1+2)+(1+2+3)+(1+2+3+4)+…..(1+2+3+4…….+n)

```
import java.io.*;
class series3
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number of ur choice");
int n=Integer.parseInt(br.readLine());
int sum=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
sum+=j;
}
}
System.out.println(sum);
}
}
```

Write a program to print the following series

4, 9, 16,25,…..

```
import java.io.*;
class series5
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number of ur choice");
int n=Integer.parseInt(br.readLine());
int sum=0;
for(int i=2;i<=n;i++)
{
double sq=Math.pow(i,2);
sum+=sq;
}
System.out.println(sum);
}
}
```