Series programs part 2
Write a program to print the following series.
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);
}
}https://youtu.be/DjipqnsypVs
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.