0Pricing
Java Academy · Lesson

The Math Class

Common math functions.

The Math Class

java.lang.Math is a built-in class of static math methods. It is in java.lang, so no import is needed. You call methods on the class: Math.sqrt(2).

Powers and Roots

Math.pow(base, exp) raises a number to a power, and Math.sqrt(x) takes a square root. Both return double.

public class Main {
    public static void main(String[] args) {
        System.out.println(Math.pow(2, 10));
        System.out.println(Math.sqrt(144));
    }
}

All lessons in this course

  1. The Math Class
  2. Generating Random Numbers
  3. Random Ranges and Shuffling
  4. Math Rounding and Limits
← Back to Java Academy