double degree = 45; // declare degree variable double radian = Math.toRadians(degree); // convert degree to radians System.out.println("The radian value is " + radian); // print radian value
double angle = 30; // declare angle variable double radian = Math.toRadians(angle); // convert angle to radians double sinValue = Math.sin(radian); // calculate sin value System.out.println("The sin value is " + sinValue); // print sin valueIn this example, Math.sin() function is used to calculate the sin value of an angle in degrees. The angle is first converted to radians using Math.toRadians() function and then passed as a parameter to the Math.sin() function. The resulting sin value is stored in the variable sinValue and printed using System.out.println(). The java.awt.Math library is part of the Java Abstract Window Toolkit (AWT) package, which provides classes for creating and managing graphical user interfaces (GUIs).