java tutorial - Java Math.abs() Method - tutorial java - java programming - learn java - java basics - java for beginners
![Java numbers abs](https://wikitechy.com/tutorials/java/img/java-images/java-numbers-abs.gif)
Learn Java - Java tutorial - Java numbers abs - Java examples - Javaprograms
Description
Method Math.abs () - gives the absolute value of the argument, in simple words - we get the modulus of a number. The argument can be int, float, long, double, short, byte.
Syntax
Variants of the method are given below:
double abs(double d)
float abs(float f)
int abs(int i)
long abs(long lng)
click below button to copy the code. By - java tutorial - team
Options
Detailed information about the parameters:
- Any primitive data type.
Return value
- In Java, Math.abs () returns the absolute value of the argument (the number module).
Sample Code
public class Test {
public static void main(String args[]){
Integer a = -8;
double d = -100;
float f = -90;
System.out.println(Math.abs(a));
System.out.println(Math.abs(d));
System.out.println(Math.abs(f));
}
}
click below button to copy the code. By - java tutorial - team
Output
8
100.0
90.0