Java Example Programs – How To Find An Absolute Value

Hey, Welcome to Practicehouse . In this post we will learn How to find an absolute value for an integer or floating point number. It’s a baby math. Absolute value is a distance so absolute value means how far a number is from ZERO .

Let’s see an example :

in this picture you can see the distance towards positive number and negative number . so it will give us the distance not the real number . For this scenario 3 is the absolute value for -3  and 5 is the absolute value for 5.
Absolute value don’t do anything with 0.

Now if we need to find an absolute value in our java program then how . Okay in java java.lang.Math.abs returns us absolute value of a number. let’s see an example program.

Let’s compile this program and run it. it will give us this output .


Okay i hope now you don’t have any doubt about absolute value and how to find an absolute value in java. that’s it for now. check out my other post. thank you for reading this post.

Leave a Reply

Notify of