25.02.2017 Views

java_tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java<br />

This will produce the following result:<br />

9<br />

5.0<br />

1092<br />

Java – abs() Method<br />

Description<br />

The method gives the absolute value of the argument. The argument can be int, float,<br />

long, double, short, byte.<br />

Syntax<br />

Following are all the variants of this method:<br />

double abs(double d)<br />

float abs(float f)<br />

int abs(int i)<br />

long abs(long lng)<br />

Parameters<br />

Here is the detail of parameters:<br />

<br />

Any primitive data type<br />

Return Value<br />

This method Returns the absolute value of the argument.<br />

Example<br />

public class Test{<br />

public static void main(String args[]){<br />

Integer a = -8;<br />

double d = -100;<br />

float f = -90;<br />

System.out.println(Math.abs(a));<br />

System.out.println(Math.abs(d));<br />

System.out.println(Math.abs(f));<br />

93

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!