Answers for "cos sin javascript"

1

sin in javascript

Math.sin(Math.PI / 2);//it uses radians, pi/2 = 90 degrees, output:1
//make a function 
const DegToRad = num => {return num * Math.PI / 180;};
Math.sin(DegToRad(90));//now its easy to read, output still 1
Posted by: Guest on July-15-2021
0

cos in javascript

import java.lang.*;

 class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 45.0;
      double y = 180.0;
   
      // convert them to radians
      x = Math.toRadians(x);
      y = Math.toRadians(y);

      // print their cosine
      System.out.println("Math.cos(" + x + ")=" + Math.cos(x));
      System.out.println("Math.cos(" + y + ")=" + Math.cos(y));
   }
}
Posted by: Guest on March-21-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language