double angle = Math.PI / 4; // angle in radians double cosine = Math.cos(angle); System.out.println(cosine); // prints 0.7071067811865475
double[] angles = {0, Math.PI / 4, Math.PI / 2, Math.PI}; for (double angle : angles) { double cosine = Math.cos(angle); System.out.printf("Cosine of %.2f radians is %.2f\n", angle, cosine); }This code calculates the cosine of four different angles (0, pi/4, pi/2, and pi) and prints the results. The java.util package is a standard library in Java that provides utility classes for common functions, such as math operations, date and time manipulation, and collections. The Math class is part of this package.