Just for Java Learning
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

29 linhas
793 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. double sumOfGeo;
  9. Scanner input = new Scanner(System.in);
  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. sumOfGeo = (a*(Math.pow(R,n)-1))/(R-1);
  17. System.out.print("The sum of Geometric Series: ");
  18. System.out.printf("%1.1f\n" , sumOfGeo);
  19. }
  20. }