[Edit]
+
0
-
0

Java Math.tan() with degrees

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
public class MathExample { static double calculateTan(double deg) { double radians = (Math.PI / 180) * deg; return Math.tan(radians); } public static void main(String[] args) { // Example: double x1 = 0.0; // beginning of calculation in degrees double x2 = 90.0; // ending of calculation degrees double dx = 30.0; // calculation step in degrees for (double deg = x1; deg <= x2; deg += dx) { double y = calculateTan(deg ); System.out.println("tan(" + deg + " deg) = " + y); } } } /* OUTPUT: tan(0.0 deg) = 0.0 tan(30.0 deg) = 0.5773502691896257 tan(60.0 deg) = 1.7320508075688767 tan(90.0 deg) = 1.633123935319537E16 */