From 18c9a0ecffc55c068219383e1b590e4d33bd6e64 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 10 Aug 2024 11:23:06 +0530 Subject: [PATCH] Upload files to "OOP/Java/Lab/Week3" --- OOP/Java/Lab/Week3/SqInvAndSinCalc.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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; } }