Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement