Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
490ff117eb
commit
ff230bd039
12
OOP/Java/Lab/Week3/SeqLadder.java
Normal file
12
OOP/Java/Lab/Week3/SeqLadder.java
Normal 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("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
OOP/Java/Lab/Week3/SqInvAndSinCalc.java
Normal file
31
OOP/Java/Lab/Week3/SqInvAndSinCalc.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user