Upload files to "OOP/Java/Lab/Week3"

This commit is contained in:
Aadit Agrawal 2024-08-10 11:20:17 +05:30
parent 490ff117eb
commit ff230bd039
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,12 @@
public class SeqLadder {
public static void main(String args[]){
int a=0;
for(int i = 1; i<5 ; i++){
for (int j = 0; j<i; j++){
System.out.print(++a+" ");
}
System.out.println("");
}
}
}

View File

@ -0,0 +1,31 @@
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);
}
}