Question: Assignment: The sum ( S _ { n } ) of the first ( n ) terms of a geometric series
Assignment: The sum Sn of the first n terms of a geometric series is:
Snaa ra ra rldotsa rn
where a is the first term of the series and r is called the common ratio.
Your task is to write a public class that uses recursion to compute the sum of the first n terms of a geometric series. Write a class named GeometricSeries that includes:
A recursive public static double method called geometricSum int n double a double r which calculates the sum of the first n terms of the geometric series for given a and r ;
A main method in your GeometricSeries class that: should terminate;
displays the message "Enter a value for the first term: and allows the user to input a double value a ;
displays the message "Enter a value for the connon ratio: and allows the user to input a double value r ;
invokes the geometricSun method and then displays the following message:
The sum of the first n terms is sum
For example, if n a and r the final message should be:
The sum of the first terms is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
