Just for Java Learning
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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