2 - Advanced Math

Get an introduction to or review of advanced math operations in Java programming.

Code HuntJava
1.0x

2 - Advanced Math

Created 3 years ago

Duration 0:02:18
lesson view count 60
Get an introduction to or review of advanced math operations in Java programming.
Select the file type you wish to download
Slide Content
Tags: Code Hunt Java
  1. Advanced Math

    Slide 2 - Advanced Math

  2. The Math class

    Slide 3 - The Math class

    • The Math class in Java contains many useful methods for mathematical operations:
    • abs(x) – computes the absolute value of x ()
    • sqrt(x) – computes the square root of x ()
    • pow(x, y) – computes x to the power of y ()
    • max(x, y) – computes the maximum (larger) of x and y
    • min(x, y) – computes the minimum (smaller) or x and y
    • These methods work for both real numbers (doubles) and integers (ints)
  3. Calling Math methods

    Slide 4 - Calling Math methods

    • To call these methods, we use the following syntax: Math.<method name>(<arguments>)
    • System.out.println(Math.abs(-4));
    • System.out.println(Math.sqrt(9));
    • System.out.println(Math.sqrt(2));
    • System.out.println(Math.pow(5, 3));
    • System.out.println(Math.pow(2, 0.5));
    • System.out.println(Math.max(5, 0));
    • System.out.println(Math.min(5, 0));