MIT-Curricular/OOP/Java/Lab/Week3/SqInvAndSinCalc.java

32 lines
940 B
Java

import java.util.Scanner;
public class SqInvAndSinCalc {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
double sum=0, sinx=0;
System.out.println("Enter the number of terms you want to check (for both Sine and Sum):");
int terms = sc.nextInt();
for(int i=1; i<=terms ; i++){
sum += Math.pow(i,-i);
}
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;
int n = 1;
for (int i = 1; i <= terms; i++) {
double term = pow(-1, n) * pow(x, 2 * n + 1) / tgamma(2 * n + 1);
sinx += term;
n++;
}
System.out.println("The value of Sin("+x+") is: "+sinx);
System.out.println("The sum is "+sum);
}
}