fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner in=new Scanner(System.in);
  13. int n;
  14. double sum=0, p;
  15. n=in.nextInt();
  16. for(int i=1; i<=n; i++){
  17. p=in.nextDouble(); //вводим значение а
  18. if(i%2==1)//определяем его знак и сумируем
  19. sum+=p;
  20. else
  21. sum+=-p;
  22. }
  23. System.out.print("Sum: " + sum);
  24. }
  25. }
Success #stdin #stdout 0.17s 321280KB
stdin
15	66 456 3334 23 0.86 -587 4332 82223 0.0008 0 -0.75 44 52 7777 43
stdout
Sum: -82108.8892