Math.cos()
Math.cos() returns the trigonometric cos value of an angle in radian.
Syntax
Math.cos(angle_in_radian)
Note that all input numbers are in Radians.
Here are some examples.
System.out.println(Math.cos(Math.PI)); //-1
System.out.println(Math.cos(Math.PI/2));//6.123233995736766E-17
System.out.println(Math.cos(2)); //-0.4161468365471424
System.out.println(Math.cos(1.22)); //0.34364574631604705
System.out.println(Math.cos(-1.22)); //0.34364574631604705
System.out.println(Math.cos(0)); // 1.0
We can use toRadians to convert degree value to radian.
Math.round() to rounds a floot or double data type to nearest integer value
System.out.println(Math.round((Math.cos(Math.toRadians(180)))));//-1
System.out.println((Math.cos(Math.toRadians(180))));//-1.0
System.out.println(Math.cos(Math.toRadians(90)));//6.123233995736766E-17
System.out.println(Math.cos(Math.PI)); //-1.0
System.out.println(Math.cos(Math.PI/2));//6.123233995736766E-17
« All Math functions
This article is written by plus2net.com team.
plus2net.com