Math Class (Cont.)
The Math.abs(x)
method returns the absolute (positive) value of x
:
System.out.println( Math.abs( 3.0-18.0 ) ); // Output: 13.0
|
The
Math.random( )
returns a random number between 0 (inclusive), and 1 (exclusive):
// Returns an integer between 0 and 99, inclusively.
System.out.println( (int) ( Math.random( ) * 100 ) );
|
For a complete reference of Math methods, go to
Java Math Methods Reference.
Fibonacci.java (calculating Fibonacci numbers)
|
|
I entered 10 puns in a pun contest
hoping one would win,
but no pun in ten did.
|