fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.math.*;
  5.  
  6. class InfiniteSum {
  7. public static void main (String[] args) throws java.lang.Exception {
  8. //Scanner read = new Scanner(System.in);
  9. double E = 1e-1;
  10. double x = -1;
  11. double sum = 0.0;
  12. for(int i = 2; Math.abs(x) > E ; i++){
  13. sum += x;
  14. x *= (-1./i);
  15. }
  16. System.out.print("Сумма = "+sum);
  17. }
  18. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
Сумма = -0.6666666666666666