Question
The question is to print the geometric progression, nth term and the sum in JAVA . All the things I have done, but the sum
The question is to print the geometric progression, nth term and the sum in JAVA. All the things I have done, but the sum is not coming right. The program is-
package abc; import java.util.Scanner; public class abc1 {
public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in);
System.out.print("Enter the value of a (First Term) : "); double firstTerm = input.nextDouble();
System.out.print("Enter the value of r (Common Ratio) : "); double commonRatio = input.nextDouble();
System.out.print("Enter the value of n (Number of terms) : "); double numberOfTerms = input.nextDouble();
double nthTerm = firstTerm * Math.pow(commonRatio, (numberOfTerms - 1));
double sum = (firstTerm * (Math.pow(commonRatio, numberOfTerms)-1)/ commonRatio-1) ; System.out.println("..."); System.out.println("The Geometric Progression is as follows :");
for(int i = 0; i
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started