Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
In mathematics, the absolute value of a number is its non-negative value, i.e. the absolute value of -2 is 2.
In order to retrieve the absolute value in Java, we use the abs()
function.
The general syntax of the abs()
function is:
public static datatype abs(datatype number)
The function takes as input the argument whose absolute value is to be determined.
The function returns the absolute value of the argument.
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) );
}
}
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
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