fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class SumNum {
  6. public static void main (String[] args) throws java.lang.Exception {
  7. Scanner read = new Scanner(System.in);
  8. int n = read.nextInt();
  9. double sum = 0;
  10. double x1;
  11. double x2 = read.nextDouble();
  12. double x3 = read.nextDouble();
  13.  
  14. for (int i = 0; i < n-2; i++ ){
  15. x1 = x2;
  16. x2 = x3;
  17. x3 = read.nextDouble();
  18. sum += (x1 + x2 + x3) * x2;
  19. }
  20. System.out.print("Сумма = "+sum);
  21. }
  22. }
Success #stdin #stdout 0.18s 322368KB
stdin
5
0 0 2 -4 7
stdout
Сумма = -24.0