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

Java Solved-Programs-Series Sum Series

The document contains a series of Java programs that generate various numerical series and calculate their sums. It includes examples such as arithmetic series, geometric series, and factorial sums, with each program clearly defined and structured. The document serves as a resource for understanding how to implement these series in Java programming.

Uploaded by

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

Java Solved-Programs-Series Sum Series

The document contains a series of Java programs that generate various numerical series and calculate their sums. It includes examples such as arithmetic series, geometric series, and factorial sums, with each program clearly defined and structured. The document serves as a resource for understanding how to implement these series in Java programming.

Uploaded by

cskwt2025
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

SOLVED PROGRAMS

SERIES AND SUM OF SERIES

Q. [Link] the programs in Java to display the first ten terms of the following
series: 1, 2, 4, 7, 11,......

public class Series1


{
public static void main(String args[]) {
for (int i = 0; i < 10; i++) {
int term = 1 + ((i * (i + 1)) / 2);
[Link](term + " ");
}
}
}
Q. 2 Print Series 1 -3 5 -7 …………n terms

class Series_Odd2
{
public void findSeries(int n)
{
int i=1, c, f=1;//
for(c=1;c<=n;c++)
{
if(f%2==0)
[Link](-i+" ");
else
[Link](i+" ");
i=i+2;
f++;
}
}
}

1
Q. 3 series :3, 6, 9, 12,......

public class Series3


{
public static void main(String args[]) {
for (int i = 3; i <= 30; i = i + 3) {
[Link](i + " ");
}
}
}

Q. 4 Print the Series: 4, 8, 16, 32,.....

public class Series4


{
public static void main(String args[]) {
for (int i = 2; i <= 11; i++) {
[Link]((int)([Link](2, i)) + " ");
}
}
}
Q.5. Print the series: 1.5, 3.0, 4.5, 6.0,

public class Series5


{
public static void main(String args[]) {
float c = 1.5f;
for (int i = 1; i <= 10; i++) {
[Link](c + " ");
c=c+1.5f;
}
}
}
Q. 6 Print the series: 4, 16, 36, 64,.........

public class Series6

2
{
public static void main(String args[]) {
for (int i = 2; i <= 20; i = i + 2) {
[Link]((i * i) + " ");
}
}
}
Q. 7 Print the series: 24, 99, 224, 399,.......

public class Series7


{
public static void main(String args[]) {
for (int i = 5; i <= 50; i = i + 5) {
int s = (i*i - 1);
[Link](s+ " ");
}
}
}

Q. 8 print the series:1, 11, 111, 1111,…………….

public class Series_book1


{
public static void main() {
int c = 1;

for (int i = 1; i <= 10; i++) {


[Link](c + ", ");
c= c * 10 + 1;
}
}
}

Programs in Java to find the sum of the following given series :

3
Q. 9 S = (1/a) + (2/a^2) + (3/a^3) + ....... to n

import [Link];

public class SeriesSumTest1


{
public static void main (String args[]) {

Scanner in = new Scanner([Link]);


[Link]("Enter a: ");
int a = [Link]();
[Link]("Enter n: ");
int n = [Link]();
double sum = 0;

for (int i = 1; i <= n; i++) {


sum += (i / [Link](a, i));
}

[Link]("Sum=" + sum);
}
}

Q. 10 S = a^2 + a^2 / 2 + a^2 / 3 + ...... + a^2 / 10


import [Link];

public class Series12_a


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a: ");
int a = [Link]();
double sum = 0.0;
for (int i = 1; i <= 10; i++){
sum =sum+ [Link](a, 2) / i;}
[Link]("Sum = " + sum);

4
}
}

Q. 11 Write a program in Java to find the sum of the given series :


S = a + a^2 / 2 + a^3 / 3 + ...... + a^10 / 10
import [Link];

public class Series12_b


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a: ");
int a = [Link]();
double sum = 0.0;
for (int i = 1; i <= 10; i++)
sum += [Link](a, i) / i;
[Link]("Sum = " + sum);
}
}

Q. 12 S = (a*2) + (a*3) + ...... + (a*20)


import [Link];

public class Series_12c


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a ");
int a = [Link]();
long sum = 0;
for (int i = 2; i <= 20; i++){
sum = sum+a * i;}
[Link]("Sum = " + sum);
}
}

5
Q. 13 S = a + a2 + a3 + ...... + an

import [Link];

public class Series12_d


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a: ");
int a = [Link]();
[Link]("Enter n: ");
int n = [Link]();
long sum = 0;
for (int i = 1; i <= n; i++)
sum += [Link](a, i);
[Link]("Sum = " + sum);
}
}

Q 14 S = 1 + 22 / a + 33 / a2 + ...... to n terms
import [Link];

public class Series_12e


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a ");
int a = [Link]();
[Link]("Enter n ");
int n = [Link]();
double sum = 1.0;
for (int i = 2; i <= n; i++){
sum =sum+ [Link](i, i) / [Link](a, i - 1);}
[Link]("Sum = " + sum);
}
}

6
Q. 15 S = 1^2/a + 3^2 / a^2 / a^3 + ...... to n terms

import [Link];

public class Series_12f


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a: ");
int a = [Link]();
[Link]("Enter n: ");
int n = [Link]();

double s = 0.0;
int c = 1;
for(int i = 1; i <= n; i++){

s =s+ [Link](c, 2) / [Link](a, i);


c =c+ 2;
}
[Link]("Sum = " + s);
}
}

Q 16 S = 1/a + 1/a2 + 1/a3 + ...... + 1/an

import [Link];

public class Series_12g


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter a: ");
int a = [Link]();
[Link]("Enter n: ");
int n = [Link]();

7
double sum = 0.0;
for (int i = 1; i <= n; i++)
sum =sum+ 1 / [Link](a, i);
[Link]("Sum = " + sum);
}
}

Q. 17. S = x/2 + x/5 + x/8 + x/11 + ...... + x/20

import [Link];

public class series_12h


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter x: ");
int x = [Link]();
double sum = 0.0;
for (int i = 2; i <= 20; i = i+3)
sum =sum+ (double)x / i;
[Link]("Sum = " + sum);
}
}

Q 18. S = 1 + (1*2) + (1*2*3) + ....... + (1*2*3* ....... * n)

import [Link];

public class Series_book10_d


{
public void computeSeriesSum() {

Scanner in = new Scanner([Link]);


[Link]("Enter n: ");
int n = [Link]();
int sum = 0, c = 1;

8
for (int i = 1; i <= n; i++) {
c=c* i;
sum = sum+c;
}

[Link]("Sum=" + sum);
}
}
Q. 19 S = 1 + (1+2) + (1+2+3) + ....... + (1+2+3+ ....... + n)

import [Link];

public class SumSeries_book10c


{
public static void main(String args[]) {

Scanner in = new Scanner([Link]);


[Link]("Enter n: ");
int n = [Link]();
int sum = 0, c = 0;

for (int i = 1; i <= n; i++) {


c =c+ i;
sum= sum+c;
}

[Link]("Sum=" + sum);
}
}

Q.20 print the series: 1, 12, 123, 1234,...

public class Series_book10e


{
public void generateSeries() {

for (int i = 1; i <= 10; i++) {

9
for (int j = 1; j <= i; j++) {
[Link](j);
}
[Link](", ");
}

}
}

10

Common questions

Powered by AI

The series follows an arithmetic pattern where each term increases by a constant difference of 3. In Java, it is implemented using a loop that increments the starting number 3 by 3 in each step until 30 is reached .

The logic utilizes nested loops; the outer loop iterates across numbers 1 to 10, and the inner loop constructs each line of the series by concatenating incremental numbers up to the current value of the outer loop. This relies on the mathematical principle of digit concatenation and sequence progression .

This series integrates both exponential growth (through powers of numbers) and exponential decay (through division by increasing powers of a constant 'a'), balancing between amplification and attenuation. This structure models complex systems where such dualities are present and convergence is achieved through a balance of competing exponential factors .

The inner loop in generating the pattern repetitively constructs each segment of the jagged sequence by iterating through numbers up to the current outer loop index. Optimization could involve reducing redundant calculations by pre-concatenating or caching partial results, thereby decreasing the time complexity in successive iterations .

The program calculates the sum by iterating through terms where each term is Math.pow(a, i) / i, where i ranges from 1 to 10. Dividing by the sequence index introduces a harmonic sequence element, where each successive term diminishes in its contribution relative to its power, simulating convergence behavior .

The series is generated using a loop where each term is calculated using the formula: term = 1 + ((i * (i + 1)) / 2). The term represents the ith term in the sequence and is computed by incrementing the current index's arithmetic operations, which is based on triangular numbers .

The series is calculated by iterating from i = 1 to n, adding (i / Math.pow(a, i)) to a cumulative sum variable. This approach relies on the mathematical concept of geometric series, where each term is a multiple of its predecessor by a certain factor (1/a).

The strategy involves using a loop where an accumulator multiplies the current iteration index to form the current factorial product, which is then added to a running sum. This method efficiently reuses the previous factorial result, reducing computational redundancy compared to recalculating factorials from scratch .

The series 1, -3, 5, -7,... is implemented by checking if the sequence index is even or odd using the modulus operator. If the index is even, the negative of the number is printed; if odd, the number itself is printed. This is achieved by checking the parity of an incrementing factor 'f' .

Using cumulative summation with incrementing sequence indices leverages systematic accumulation rather than repeated additions for each series part by reusing sub-results to form the next, substantially optimizing performance by minimizing redundant operations, a critical principle in algorithm design .

You might also like