// This example uses the java.lang.Math library, which consists of // static fields and methods // // This example shows you how to CALL upon static features of a library // Format: className.member // // If you see a CLASS name on the left of the dot-operator, the // thing on the right MUST be a static member class MathExample { public static void main(String[] args) { System.out.printf("PI to 3 decimal places = %.3f\n", Math.PI); System.out.printf("E to 3 decimal places = %.3f\n", Math.E); int x = 10, y = -5, z = -20; int a1; a1 = Math.abs(x); System.out.println("Absolute value of " + x + " is " + a1); System.out.println("Absolute value of " + y + " is " + Math.abs(y) ); System.out.println("Absolute value of " + z + " is " + Math.abs(z) ); double ans = Math.pow(y,3); int answer = (int)ans; System.out.println(y + " raised to the power of 3 = " + answer); System.out.println(x + " raised to the power of 4 = " + (int)Math.pow(x, 4) ); double randNum; randNum = Math.random(); System.out.println("Random number is: " + randNum); int dieRoll = (int)(Math.random() * 6) + 1; System.out.println("Rolling a die: " + dieRoll); } }