Guest User

Untitled

a guest
Oct 21st, 2019
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.math.*;
  2. public class numberfun {
  3. public static void main(String[] args){
  4. System.out.println(pi());
  5. System.out.println(euler());
  6. }
  7. public static double pi(){
  8. double sum=0;
  9. for (double i=1, pos=1;pos<=1000;pos++,i+=2){
  10. sum=pos%2==1?sum+4/i:sum-4/i;
  11. }
  12. return sum;
  13. }
  14. public static double euler(){
  15. double sum=0;
  16. for (double i=0;i<=170;i++){
  17. sum+=(1.0/factorial(i));
  18. }
  19. return sum;
  20. }
  21. public static double factorial(double n){
  22. double prod=1;
  23. for (int i=2;i<=n;i++){
  24. prod*=i;
  25. }
  26. return prod;
  27. }
  28. }
RAW Paste Data