Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Main {
- public static void main(String[] args) {
- System.out.println(sin(0.1, 10));
- }
- public static int factorial(int n){
- if(n <= 0)
- return 1;
- return factorial(n - 1) * n;
- }
- public static double sin(double x, int n){
- double ret = 0.0;
- if(n < 1)
- return 1;
- for(int i = 0; i <= n; i++)
- ret += Math.pow(-1, i) * Math.pow(x, 1 + (2 * i))
- / factorial(1 + (2 * i));
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement