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 double p(int x)
  11. {
  12. double r = 1.0;
  13. for (int i = 2; i <= x; i++) r *= i;
  14. return r;
  15. }
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. // your code goes here
  19. Scanner s = new Scanner(System.in);
  20. int n = s.nextInt();
  21. if (n > 50 || n < 0)
  22. {
  23. System.out.println("不在范围!");
  24. }
  25. else
  26. {
  27. double d = 0;
  28. for (int i = 1; i <= n; i++)
  29. d += p(i);
  30. System.out.println("结果=" + d);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.07s 2184192KB
stdin
4
stdout
结果=33.0