304 North Cardinal St.
Dorchester Center, MA 02124

# Finding the absolute value in Java

## Finding the absolute value in Java Answer

In mathematics, the absolute value of a number is its non-negative value, i.e. the absolute value of -2 is 2.

## Absolute value in Java

In order to retrieve the absolute value in Java, we use the `abs()` function.

## Syntax

The general syntax of the `abs()` function is:

``public static datatype abs(datatype number)``

### Parameters

The function takes as input the argument whose absolute value is to be determined.

### Return value

The function returns the absolute value of the argument.

## Example

Let’s take a look at how we can find the absolute value using the `abs()` function!

``````class HelloWorld {
public static void main( String args[] ) {
/* Converting Integer values */
int x = 123;
int y = -789;
System.out.printf( "Absolute Value of x: %d \n", Math.abs(x) );
System.out.printf( "Absolute Value of y: %d \n", Math.abs(y) );

/* Converting Floating Point values */
float a = 1.23f;
float b = -7.9f;
System.out.printf( "Absolute Value of a: %f \n", Math.abs(a) );
System.out.printf( "Absolute Value of b: %f \n", Math.abs(b) );
}
}``````
##### Finding the absolute value in Java Review:

In our experience, we suggest you solve this Finding the absolute value in Java and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Finding the absolute value in Java

Find on Educative

##### Conclusion:

I hope this Finding the absolute value in Java would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions