Question: Write a Java program named SumOfSeries to calculate the sum of the following series sum = a 0 + a 1 + a 2 +
sum = a 0 + a 1 + a 2 + a 3 + + a n
The program should have two static methods main and calPower . The main method should:
1. Allow the user to enter the base value a in double and the last terms power value n as in integer
2. Initialize the variable sum with 0.0
3. Call the method calPower for n+1 times, by sending the base value a and the power value from 0 to n
4. For each call of calPower method, receive the result and calculate the sum immediately.
5. Print the sum value in two decimal places
The calPower method should: 1. Receive the base(b) and power (p) values 2. Calculate r= bp 3. return the value r For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac), -Font fan -Font si
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
