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. int x= 3;
  13. double product=1,sum=0;
  14. for(int i=1;i<=x;i++)
  15. {
  16. product*=i;
  17. sum+=1.0/product;
  18. System.out.print("1/" + product);
  19.  
  20. if(i == x){
  21. System.out.print(" = " + sum);
  22. }
  23. else {
  24. System.out.print(" + ");
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
1/1.0 + 1/2.0 + 1/6.0 = 1.6666666666666667