diff --git a/OOP/Java/Lab/Week3/SqInvAndSinCalc.java b/OOP/Java/Lab/Week3/SqInvAndSinCalc.java index 7e269b1..32d6899 100644 --- a/OOP/Java/Lab/Week3/SqInvAndSinCalc.java +++ b/OOP/Java/Lab/Week3/SqInvAndSinCalc.java @@ -14,18 +14,26 @@ public class SqInvAndSinCalc { System.out.println("Enter the input in degrees for the Sine function:"); double y = sc.nextDouble(); - double x = (y) * (3.1415926 / 180.0); - double sinx = x; + double x = y * (3.1415926 / 180.0); + sinx = x; int n = 1; - + for (int i = 1; i <= terms; i++) { - double term = pow(-1, n) * pow(x, 2 * n + 1) / tgamma(2 * n + 1); + double term = Math.pow(-1, n) * Math.pow(x, 2 * n + 1) / factorial(2 * n + 1); sinx += term; n++; } - System.out.println("The value of Sin("+x+") is: "+sinx); + System.out.println("The value of Sin(" + x + ") is: " + sinx); - System.out.println("The sum is "+sum); + System.out.println("The sum is " + sum); + } + + public static double factorial(int n) { + double result = 1; + for (int i = 2; i <= n; i++) { + result *= i; + } + return result; } }