About 474,000 results
Open links in new tab
  1. Java's Math class provides a variety of methods to perform mathematical operations. Here's an example demonstrating some commonly used methods.

    public class MathExample {
    public static void main(String[] args) {
    // Find the maximum and minimum of two numbers
    System.out.println("Max of 5 and 10: " + Math.max(5, 10)); // Output: 10
    System.out.println("Min of 5 and 10: " + Math.min(5, 10)); // Output: 5

    // Calculate square root
    System.out.println("Square root of 64: " + Math.sqrt(64)); // Output: 8.0

    // Absolute value
    System.out.println("Absolute value of -4.7: " + Math.abs(-4.7)); // Output: 4.7

    // Power calculation
    System.out.println("2 raised to the power of 8: " + Math.pow(2, 8)); // Output: 256.0

    // Rounding methods
    System.out.println("Round 4.6: " + Math.round(4.6)); // Output: 5
    System.out.println("Ceil of 4.1: " + Math.ceil(4.1)); // Output: 5.0
    System.out.println("Floor of 4.9: " + Math.floor(4.9)); // Output: 4.0

    // Generate a random number between 0 and 100
    int randomNum = (int) (Math.random() * 101);
    System.out.println("Random number between 0 and 100: " + randomNum);
    }
    }
    Copied!
    Like
    Dislike
  2. Math (Java Platform SE 8 ) - Oracle Help Center

      • sin. public static double sin(double a) Returns the trigonometric sine of an angle. Special cases: If …
      • cos. public static double cos(double a) Returns the trigonometric cosine of an angle. Special …
      • tan. public static double tan(double a) Returns the trigonometric tangent of an angle. Special …
      • asin. public static double asin(double a) Returns the arc sine of a value; the returned angle is in the …
      • acos. public static double acos(double a) Returns the arc cosine of a value; the returned angle is in …
  3. Java Math Class - GeeksforGeeks

    Jul 23, 2025 · Math class consists of methods that can perform mathematical operations and can make long calculations a bit easier. Let us check the method provided in the Math class.

  4. Java Math Guide for Beginners | Medium

    Mar 9, 2024 · Explore our beginner's guide to Java Math, including basic operations, the Math class, and real-world examples, to boost your Java programming skills.