Issue
I have been stuck on this for a very long bit of time. How do I make my calculator calculate in degrees rather than radians. I tried Math.toDegrees but it did not work. Thank you if you decide to help.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// END USER INPUT VALUE IN DEGREES
System.out.println("Please input a value to recieve the Trigonemetric value in degrees ");
double degrees = scanner.nextDouble();
double sineOfAngle = Math.sin(degrees);
double cosOfAngle = Math.cos(degrees);
double tanOfAngle = Math.tan(degrees);
System.out.println();
System.out.println("The Sine of " + degrees + " degrees is : "
+ sineOfAngle);
System.out.println("The Cosine of " + degrees + " degrees is : "
+ cosOfAngle);
System.out.println("The Tangent of " + degrees + " degrees is : "
+ tanOfAngle);
}
}
Solution
use Math.toRadians()
, You want to convert the degrees to radians because the Math trigonometric functions parameters should be in radians:
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// END USER INPUT VALUE IN DEGREES
System.out.println("Please input a value to recieve the Trigonemetric value in degrees ");
double degrees = scanner.nextDouble();
double sineOfAngle = Math.sin(Math.toRadians(degrees));
double cosOfAngle = Math.cos(Math.toRadians(degrees));
double tanOfAngle = Math.tan(Math.toRadians(degrees));
System.out.println();
System.out.println("The Sine of " + degrees + " degrees is : "
+ sineOfAngle);
System.out.println("The Cosine of " + degrees + " degrees is : "
+ cosOfAngle);
System.out.println("The Tangent of " + degrees + " degrees is : "
+ tanOfAngle);
}
}
Answered By - ATP
Answer Checked By - Katrina (JavaFixing Volunteer)