Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make my calculator this to calculate in degrees rather than radians

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);
    
 }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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);
    
 }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading