Just for Java Learning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
791 B

  1. //Math.pow(R,n), R to the power of n
  2. //a * R to the power of n and divided by R - 1
  3. package tutorial;
  4. import java.util.Scanner;
  5. public class CalSumOfGeo {
  6. public static void main(String[] args){
  7. double a, R, n;
  8. Scanner input = new Scanner(System.in);
  9. double sumofGS;
  10. System.out.print("Enter the first number of the sequence: ");
  11. a = input.nextDouble();
  12. System.out.print("Enter the common ratio of the sequence: ");
  13. R = input.nextDouble();
  14. System.out.print("Enter the number of the terms of the sequence: ");
  15. n = input.nextDouble();
  16. sumofGS = (a*(Math.pow(R,n)-1))/(R-1);
  17. System.out.print("The sum of Geometric Series: ");
  18. System.out.printf("%1.1f\n" , sumofGS);
  19. }
  20. }