Just for Java Learning
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

29 行
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. }