0% found this document useful (0 votes)
2 views

Code

The SeriesCalculator class contains two overloaded methods to compute different mathematical series. The first method calculates the sum of a series based on a given parameter 'a' and the number of terms 'n', while the second method computes a fixed series with predefined numerators and denominators. The main method demonstrates the usage of both series calculations.

Uploaded by

Jay Prakash Giri
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)
2 views

Code

The SeriesCalculator class contains two overloaded methods to compute different mathematical series. The first method calculates the sum of a series based on a given parameter 'a' and the number of terms 'n', while the second method computes a fixed series with predefined numerators and denominators. The main method demonstrates the usage of both series calculations.

Uploaded by

Jay Prakash Giri
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/ 2

public class SeriesCalculator {

// Overloaded method to compute the first series

public void series(double a, int n) {


double sum = 0;
for (int i = 0; i < n; i++) {
sum += (1 + 3 * i) / Math.pow(a, i + 1);
}
System.out.println("Sum of the series (1/a + 4/a^2 + 7/a^3 + ...) up to " + n
+ " terms: " + sum);
}

// Overloaded method to compute the second series


public void series() {

double[] numerators = {1, 2, 3, 4};


double[] denominators = {41, 31, 21, 11};
double sum = 0;

for (int i = 0; i < numerators.length; i++) {


sum += numerators[i] / denominators[i];

System.out.println("Sum of the series (1/41 + 2/31 + 3/21 + 4/11): " + sum);


}

public static void main(String[] args) {

SeriesCalculator calculator = new SeriesCalculator();

// Calling the first overloaded method


calculator.series(2.0, 5); // Example values for a and n

// Calling the second overloaded method

calculator.series();
}
}

You might also like