Java Math Class — Free Java Tutorial
Learn Java Math Class in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Java Math Class in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Java Math Class in Java
The java.lang.Math class provides static utility methods for mathematical operations. It is auto-imported — no import statement needed.
Key methods: Math.abs() (absolute value), Math.pow(base, exp), Math.sqrt(), Math.ceil(), Math.floor(), Math.round(), Math.max(), Math.min().
Math.random() returns a random double in [0.0, 1.0). To get a random int from 0 to n-1: (int)(Math.random() * n).
Math.PI and Math.E are built-in constants (double precision). Use them instead of hardcoding 3.14159.
Java Math Class — Syntax
Math.abs(-5) // 5 Math.pow(2, 10) // 1024.0 Math.sqrt(144) // 12.0 Math.ceil(4.2) // 5.0 Math.floor(4.9) // 4.0 Math.round(4.5) // 5 Math.max(10, 20) // 20 Math.min(10, 20) // 10 Math.random() // 0.0 to 0.999... (int)(Math.random() * 6) + 1
Learn Java Math Class step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →