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

Series Program Solution

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)
7 views10 pages

Series Program Solution

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
You are on page 1/ 10

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++)
System.out.println(i*i);
}}
b) //1,2,4,7,11…….
class Q1
{static void series2()
{int x=1;
for(int i=1;i<=10;i++ )
{System.out.println(x);
x=x+i;
}
}}
c)//3,6,9,12…..
class Q1
{static void series3()
{
for(int i=1;i<=10;i++ )
System.out.println(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;
System.out.println(i); }
}}
e)//1.5,3.0,4.5,6.0……
class Q1
{static void series5()
{
for(int j=1;j<=10;j++)
System.out.println(j*1.5);
}}
f)//0,7,26…..
class Q1
{static void series6()
{
for(int p=1;p<=10;p++ )
System.out.println((int)Math.pow(p,3)-1);
}}
g)//1,9,25,49
class Q1
{static void series7()
{
for(int p=1;p<=19;p=p+2)
System.out.println(p*p);
}}
h)//4,16,36,64….
class Q1
{static void series8()
{
for(int p=2;p<=20;p=p+2)
System.out.println(p*p);
}}
i)//0,3,8,15…
class Q1
{static void series11()
{
for(int p=1;p<=10;p++)
System.out.println(p*p-1);
}}
j)//24,99,224,399,………..
class Q1
{static void series10()
{
for(int p=5;p<=50;p=p+5 )
System.out.println(p*p-1);
}}
k)//2,5,10,17,…..
class Q1
{static void series11()
{
for(int p=1;p<=10;p++)
System.out.println(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(System.in);
int sum=0;
for(int j=1;j<=20;j++)
sum+=j*j;
System.out.println(“Sum of the series=”+sum);
}}
2. //1+ 1/2+ 1/3 +…….1/20
import java.util.*;
class Q8 {
static void main()
{
Scanner sn=new Scanner(System.in);
double sum=0;
for(int p=1;p<=20;p++)
sum+=1.0/p;
System.out.println(“Sum of the series=”+sum);
}}
3. //1+ 1/3 + 1/5…….1/19
import java.util.*;
class Q8 {
static void main()
{
Scanner sn=new Scanner(System.in);
double sum=0;
for(int p=1;p<=19;p=p+2)
sum+=1.0/p;
System.out.println(“Sum of the series=”+sum);
}}
4.//1/2 +2/3 +3/4+……19/20
import java.util.*;
class Q8 {
static void main()
{
Scanner sn=new Scanner(System.in);
double term,sum=0;
for(int p=1;p<=19;p++)
{term=p/(p+1.0);
sum+=term;
}
System.out.println(“Sum of the series=”+sum);
}}
5.//2-4+6-8+…….-20
import java.util.*;
class Q8 {
static void main()
{
Scanner sn=new Scanner(System.in);
int sum=0;
for(int i=2;i<=20;i=i+2)
{
if(i%4==0)
sum-=i;
else
sum+=i;
}
System.out.println(“Sum of the series=”+sum);
}}
6.//(1*2) +(2*3)+……..(19*20)
import java.util.*;
class Q8 {
static void main()
{
Scanner sn=new Scanner(System.in);
int sum=0;
for(int p=1;p<=19;p++)
sum+=p*(p+1);
System.out.println(“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;
}
System.out.println(“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=Math.pow(a,i)/i;
sum+=term;
}
System.out.println(“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;
}
System.out.println(“Sum=”+sum);
}}
// S= a1 + a2 + a3 + ………………….+ an
import java.util.*;
class Q12d {
static void main()
{Scanner sn=new Scanner(System.in);
int a,n;
double sum=0;
System.out.println(“Enter the value of a”);
a=sn.nextInt();
System.out.println(“Enter the value of n ie (power of the last term)”);
n=sn.nextInt();
for(int i=1;i<=n;i++)
sum+=Math.pow(a,i);
System.out.println(“Sum=”+sum);
}}
//S= 1 + 22/a + 33/a2 + …………….to n terms
import java.util.*;
class Q12e {
static void main()
{Scanner sn=new Scanner(System.in);
int a,n;
double sum=0,term;
System.out.println(“Enter the value of a”);
a=sn.nextInt();
System.out.println(“Enter the number of terms”);
n=sn.nextInt();
for(int i=1;i<=n;i++)
{term=Math.pow(i,i)/Math.pow(a,(i-1));
sum+=term;
}
System.out.println(“Sum=”+sum);
}}
S= 12/a + 32/a2 + 52/a3…………… to n terms
import java.util.*;
class Q12f {
static void main()
{Scanner sn=new Scanner(System.in);
int a,n;
double sum=0,term;
System.out.println(“Enter the value of a”);
a=sn.nextInt();
System.out.println(“Enter the number of terms”);
n=sn.nextInt();
for(int i=1,x=1;x<=n;i=i+2,x++)
{term=Math.pow(i,2)/Math.pow(a,x);
sum+=term;
}
System.out.println(“Sum=”+sum);
}}
// S=1/a + 1/a2 + 1/a3 + ……………+ 1/an
import java.util.*;
class Q12g {
static void main()
{Scanner sn=new Scanner(System.in);
int a,n;
double sum=0;
System.out.println(“Enter the value of a”);
a=sn.nextInt();
System.out.println(“Enter the value of n ie (power of the last term)”);
n=sn.nextInt();
for(int i=1;i<=n;i++)
sum+=1.0/Math.pow(a,i);
System.out.println(“Sum=”+sum);
}}
// S=x/2 + x/5 + x/8 + x/11…………+ x/20
import java.util.*;
class Q12h {
static void main()
{Scanner sn=new Scanner(System.in);
int x;
double sum=0;
System.out.println(“Enter the value of x”);
x=sn.nextInt();
for(double i=2.0;i<=20;i=i+3)
sum+=x/i;
System.out.println(“Sum=”+sum);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy