0% found this document useful (0 votes)
114 views10 pages

Java Series Program Solutions

The document provides Java programs to display the first ten terms of various mathematical series and calculate the sums of specific series. It includes solutions for series such as squares, arithmetic sequences, and geometric progressions, along with summation formulas. Each program is structured in a class format with methods for each series and includes comments for clarity.

Uploaded by

Jahnavi Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views10 pages

Java Series Program Solutions

The document provides Java programs to display the first ten terms of various mathematical series and calculate the sums of specific series. It includes solutions for series such as squares, arithmetic sequences, and geometric progressions, along with summation formulas. Each program is structured in a class format with methods for each series and includes comments for clarity.

Uploaded by

Jahnavi Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Solutions of Series Program

1) Write the programs in Java to display the first ten terms of the following series:
1. 1, 4, 9, 16………………
2. 1, 2, 4, 7, 11,……………
3. 3, 6, 9, 12………………
4. 4, 8, 16, 32……………..
5. 1.5, 3.0, 4.5, 6.0………..
6. 0, 7, 26…………………
7. 1, 9, 25, 49……………..
8. 4, 16, 36, 64……………
9. 0, 3, 8, 15………………
10. 24, 99, 224, 399………..
11. 2, 5, 10, 17……………..
Solution:
a)//1,4,9,16……
class Q1
{static void series1()
{
for(int i=1;i<=10;i++)
[Link](i*i);
}}
b) //1,2,4,7,11…….
class Q1
{static void series2()
{int x=1;
for(int i=1;i<=10;i++ )
{[Link](x);
x=x+i;
}
}}
c)//3,6,9,12…..
class Q1
{static void series3()
{
for(int i=1;i<=10;i++ )
[Link](i*3);
}}
d)//4,8,16,32
class Q1
{static void series4()
{int i=2;
for(int p=1;p<=10;p++ )
{i=i*2;
[Link](i); }
}}
e)//1.5,3.0,4.5,6.0……
class Q1
{static void series5()
{
for(int j=1;j<=10;j++)
[Link](j*1.5);
}}
f)//0,7,26…..
class Q1
{static void series6()
{
for(int p=1;p<=10;p++ )
[Link]((int)[Link](p,3)-1);
}}
g)//1,9,25,49
class Q1
{static void series7()
{
for(int p=1;p<=19;p=p+2)
[Link](p*p);
}}
h)//4,16,36,64….
class Q1
{static void series8()
{
for(int p=2;p<=20;p=p+2)
[Link](p*p);
}}
i)//0,3,8,15…
class Q1
{static void series11()
{
for(int p=1;p<=10;p++)
[Link](p*p-1);
}}
j)//24,99,224,399,………..
class Q1
{static void series10()
{
for(int p=5;p<=50;p=p+5 )
[Link](p*p-1);
}}
k)//2,5,10,17,…..
class Q1
{static void series11()
{
for(int p=1;p<=10;p++)
[Link](p*p+1);
}}
2) Write a program in Java to find the sum of the given series:
1. 1+4+9+……………………………..400
2. 1+ 1/2+ 1/3 +…………………….1/20
3. 1+ 1/3 + 1/5……………………..1/19
4. 1/2 +2/3 +3/4+…………………19/20
5. 2 – 4 + 6 – 8 +……………………-20
6. (1*2) +(2*3)+……………………(19*20)
Solution:
1. //1+4+9+……400
class Q8 {
static void main()
{
Scanner sn=new Scanner([Link]);
int sum=0;
for(int j=1;j<=20;j++)
sum+=j*j;
[Link](“Sum of the series=”+sum);
}}
2. //1+ 1/2+ 1/3 +…….1/20
import [Link].*;
class Q8 {
static void main()
{
Scanner sn=new Scanner([Link]);
double sum=0;
for(int p=1;p<=20;p++)
sum+=1.0/p;
[Link](“Sum of the series=”+sum);
}}
3. //1+ 1/3 + 1/5…….1/19
import [Link].*;
class Q8 {
static void main()
{
Scanner sn=new Scanner([Link]);
double sum=0;
for(int p=1;p<=19;p=p+2)
sum+=1.0/p;
[Link](“Sum of the series=”+sum);
}}
4.//1/2 +2/3 +3/4+……19/20
import [Link].*;
class Q8 {
static void main()
{
Scanner sn=new Scanner([Link]);
double term,sum=0;
for(int p=1;p<=19;p++)
{term=p/(p+1.0);
sum+=term;
}
[Link](“Sum of the series=”+sum);
}}
5.//2-4+6-8+…….-20
import [Link].*;
class Q8 {
static void main()
{
Scanner sn=new Scanner([Link]);
int sum=0;
for(int i=2;i<=20;i=i+2)
{
if(i%4==0)
sum-=i;
else
sum+=i;
}
[Link](“Sum of the series=”+sum);
}}
6.//(1*2) +(2*3)+……..(19*20)
import [Link].*;
class Q8 {
static void main()
{
Scanner sn=new Scanner([Link]);
int sum=0;
for(int p=1;p<=19;p++)
sum+=p*(p+1);
[Link](“Sum of the series=”+sum);
}}
12) Write a program in Java to find the sum of the given series:
1. S=a2 + a2/2 + a2/3 + …………….+ a2/10
2. S= a1 + a2/2 + a3/3 + …………….+ a10/10
3. S=(a*2) + (a*3) +…………………+ (a*20)
4. S= a1 + a2 + a3 + ………………….+ an
5. S= 1 + 22/a + 33/a2 + …………….to n terms
6. S= 12/a + 32/a2 + 52/a3…………… to n terms
7. S=1/a + 1/a2 + 1/a3 + ……………+ 1/an
8. S=x/2 + x/5 + x/8 + x/11…………+ x/20
Solution:
// S=a2 + a2/2 + a2/3 + …………….+ a2/10
class Q12a {
static void main(double a)
{double term,sum=0;
for(int i=1;i<=10;i++)
{term=a*a/i;
sum+=term;
}
[Link](“Sum=”+sum);
}}
// S= a1 + a2/2 + a3/3 + …………….+ a10/10
class Q12b {
static void main(double a)
{double term,sum=0;
for(int i=1;i<=10;i++)
{term=[Link](a,i)/i;
sum+=term;
}
[Link](“Sum=”+sum);
}}
// S=(a*2) + (a*3) +…………………+ (a*20)
class Q12c {
static void main(double a)
{double term,sum=0;
for(int i=2;i<=20;i++)
{term=a*i;
sum+=term;
}
[Link](“Sum=”+sum);
}}
// S= a1 + a2 + a3 + ………………….+ an
import [Link].*;
class Q12d {
static void main()
{Scanner sn=new Scanner([Link]);
int a,n;
double sum=0;
[Link](“Enter the value of a”);
a=[Link]();
[Link](“Enter the value of n ie (power of the last term)”);
n=[Link]();
for(int i=1;i<=n;i++)
sum+=[Link](a,i);
[Link](“Sum=”+sum);
}}
//S= 1 + 22/a + 33/a2 + …………….to n terms
import [Link].*;
class Q12e {
static void main()
{Scanner sn=new Scanner([Link]);
int a,n;
double sum=0,term;
[Link](“Enter the value of a”);
a=[Link]();
[Link](“Enter the number of terms”);
n=[Link]();
for(int i=1;i<=n;i++)
{term=[Link](i,i)/[Link](a,(i-1));
sum+=term;
}
[Link](“Sum=”+sum);
}}
S= 12/a + 32/a2 + 52/a3…………… to n terms
import [Link].*;
class Q12f {
static void main()
{Scanner sn=new Scanner([Link]);
int a,n;
double sum=0,term;
[Link](“Enter the value of a”);
a=[Link]();
[Link](“Enter the number of terms”);
n=[Link]();
for(int i=1,x=1;x<=n;i=i+2,x++)
{term=[Link](i,2)/[Link](a,x);
sum+=term;
}
[Link](“Sum=”+sum);
}}
// S=1/a + 1/a2 + 1/a3 + ……………+ 1/an
import [Link].*;
class Q12g {
static void main()
{Scanner sn=new Scanner([Link]);
int a,n;
double sum=0;
[Link](“Enter the value of a”);
a=[Link]();
[Link](“Enter the value of n ie (power of the last term)”);
n=[Link]();
for(int i=1;i<=n;i++)
sum+=1.0/[Link](a,i);
[Link](“Sum=”+sum);
}}
// S=x/2 + x/5 + x/8 + x/11…………+ x/20
import [Link].*;
class Q12h {
static void main()
{Scanner sn=new Scanner([Link]);
int x;
double sum=0;
[Link](“Enter the value of x”);
x=[Link]();
for(double i=2.0;i<=20;i=i+3)
sum+=x/i;
[Link](“Sum=”+sum);

You might also like