Thursday, 18 December 2014

// The "MathMethodExamples1A" class.
// (from the Carter book)

// Example--Parts 1, 2 and 3:  Using Math.abs, Math.sqrt
// and Math.pow.

// Display the exact output of each of the following statements
// with your answer rounded up to the nearest 2 decimal places.
// Part 1: Math.abs returns any type except for boolean.
// Part 2: Math.sqrt returns the square root of the given positive value.
// Part 3: Math.pow returns the given positive value to its given power.

public class MathMethodExamples1A
{
    public static void main (String[] args)
    {
        // Part 1 (a, b, c & d) -- Math.abs:
        System.out.println ("Math.abs(-13) = " + (Math.abs (-13)));
        //_________________________________________
        System.out.println ("Math.abs(7.2) = " + (Math.abs (7.2)));
        //_________________________________________
        System.out.println ("Math.abs(-4.4e-3) = " + (Math.abs (-4.4e-3)));
        //_________________________________________
        System.out.println ("Math.abs(-645) = " + (Math.abs (-645)));
        //_________________________________________
        // Part 2 (a, b & c) -- Math.sqrt:
        System.out.println ("Math.sqrt(36) = " + (Math.sqrt (36)));
        //_________________________________________
        System.out.println ("Math.sqrt(7.0) = " + (Math.sqrt (7.0)));
        //_________________________________________
        System.out.println ("Math.sqrt(-7.0) = " + (Math.sqrt (-7.0)));
        //_________________________________________
        // Part 3 (a, b, c & d) -- Math.pow:
        System.out.println ("Math.pow(9, 1.0/3.0) = " + (Math.pow (9, 1.0 / 3.0)));
        //_________________________________________
        System.out.println ("Math.pow(3, 10) = " + (Math.pow (3, 10)));
        //_________________________________________
        System.out.println ("Math.pow(-32.0, 2) = " + Math.pow (-32.0, 2));
        //_________________________________________
        System.out.println ("(int)Math.pow(100, 0.25) = " + ((int) Math.pow (100, 0.25)));
        //_________________________________________

    } // main method
} // MathMethodsExamples1 class

No comments:

Post a Comment