Math Class
Math has abs, max, min, pow, sqrt, round, floor, ceil and random.
Example
public class Main {
public static void main(String[] args) {
System.out.println(Math.abs(-5) + " " + Math.max(3, 9) + " " + Math.pow(2, 10));
System.out.println(Math.sqrt(16) + " " + Math.round(2.5) + " " + Math.floor(-1.5));
}
}Result
5 9 1024.0 4.0 3 -2.0
Exercise
Square root.
Math.(16)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.