How to get the cosine of a number (double) in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        System.out.println("Math.cos(-1) = " + Math.cos(-1));
        System.out.println("Math.cos(1) = " + Math.cos(1));
        System.out.println("Math.cos(0) = " + Math.cos(0));
        System.out.println("Math.cos(-0) = " + Math.cos(-0));
        System.out.println("Math.cos(0.9) = " + Math.cos(0.9));
        System.out.println("Math.cos(Math.PI) = " + Math.cos(Math.PI));
        System.out.println("Math.cos(Math.PI * 2) = " + Math.cos(Math.PI * 2));
        System.out.println("Math.cos(Math.PI / 2) = " + Math.cos(Math.PI / 2));
        System.out.println("Math.cos(Math.PI / 3) = " + Math.cos(Math.PI / 3));
        System.out.println("Math.cos(45) = " + Math.cos(45));
    }
}
 
/*
run:

Math.cos(-1) = 0.5403023058681398
Math.cos(1) = 0.5403023058681398
Math.cos(0) = 1.0
Math.cos(-0) = 1.0
Math.cos(0.9) = 0.6216099682706644
Math.cos(Math.PI) = -1.0
Math.cos(Math.PI * 2) = 1.0
Math.cos(Math.PI / 2) = 6.123233995736766E-17
Math.cos(Math.PI / 3) = 0.5000000000000001
Math.cos(45) = 0.5253219888177297
 
*/

 



answered Sep 8, 2016 by avibootz

Related questions

1 answer 274 views
1 answer 229 views
1 answer 130 views
1 answer 145 views
1 answer 142 views
1 answer 216 views
1 answer 204 views
...