How to Use Math.abs(x) in Java


In this example we will show you how to use math.abs(x) to return the absolute (positive) value of x in Java.

Source Code

package com.beginner.examples;

public class Abs {
  public static void main(String[] args) {
    System.out.println(Math.abs(-3)); // return the absolute (positive) value
  }
}

Output:

3
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments