SHARE
TWEET

Untitled

a guest Jun 20th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Main {
  2.   public static void main(String[] args) {
  3.     System.out.println(sin(0.1, 10));
  4.   }
  5.  
  6.   public static int factorial(int n){
  7.     if(n <= 0)
  8.       return 1;
  9.    
  10.     return factorial(n - 1) * n;
  11.   }
  12.  
  13.   public static double sin(double x, int n){
  14.     double ret = 0.0;
  15.  
  16.     if(n < 1)
  17.       return 1;
  18.    
  19.     for(int i = 0; i <= n; i++)
  20.       ret += Math.pow(-1, i) * Math.pow(x, 1 + (2 * i))
  21.         / factorial(1 + (2 * i));
  22.  
  23.     return ret;
  24.   }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top