forked from Kyle-Pu/Mathematics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinverse.java
111 lines (76 loc) · 2.61 KB
/
inverse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.Scanner;
public class inverse {
public static void main(String[] args){
System.out.println("Welcome to the inverse trigonometry calculator!");
Scanner scan = new Scanner(System.in);
//Prompt user for which trigonometry function
System.out.println("What trigonometry function do you want to use? :"
+ "\n 1 Cosecant"
+ "\n 2 Secant"
+ "\n 3 Cotangent\n");
int userChoice = scan.nextInt();
switch(userChoice){
case 1: cosec(); break;
case 2: sec(); break;
case 3: cot(); break;
default: System.out.println("Invalid Choice. \n Exiting!");
}
}
public static double cosec(){
//Ask for user input
System.out.print("Enter an angle in degrees: ");
//use scanner to read the console input
Scanner scan = new Scanner(System.in);
//Assign the user to String variable
String s = scan.nextLine();
//close the scanner object
scan.close();
//convert the string input to double
double value = Double.parseDouble(s);
//convert the value to radians
double valueRadians = Math.toRadians(value);
Math.sin(valueRadians);
//get the cosec of the angle
double cosecValue = 1.0/Math.sin(valueRadians);
System.out.println("cosec of " + s + " is: " + cosecValue);
return cosecValue;
}
public static double sec(){
//Ask for user input
System.out.print("Enter an angle in degrees: ");
//use scanner to read the console input
Scanner scan = new Scanner(System.in);
//Assign the user to String variable
String s = scan.nextLine();
//close the scanner object
scan.close();
//convert the string input to double
double value = Double.parseDouble(s);
//convert the value to radians
double valueRadians = Math.toRadians(value);
Math.cos(valueRadians);
//get the sec of the angle
double secValue = 1.0/Math.cos(valueRadians);
System.out.println("sec of " + s + " is: " + secValue);
return secValue;
}
public static double cot(){
//Ask for user input
System.out.print("Enter an angle in degrees: ");
//use scanner to read the console input
Scanner scan = new Scanner(System.in);
//Assign the user to String variable
String s = scan.nextLine();
//close the scanner object
scan.close();
//convert the string input to double
double value = Double.parseDouble(s);
//convert the value to radians
double valueRadians = Math.toRadians(value);
Math.tan(valueRadians);
//get the cot of the angle
double cotValue = 1.0/Math.tan(valueRadians);
System.out.println("cot of " + s + " is: " + cotValue);
return cotValue;
}
}