Math.abs(x)
method returns the absolute (positive) value of x
:
|
Math.random( )
returns a random number between 0 (inclusive), and 1 (exclusive):
|
|
|
/********************************************************** * * * Fibonacci numbers are starting from 0 and 1 such * * that each number is the sum of the two preceding * * ones. For example, 0, 1, 1, 2, 3, 5, 8, 13, ... * * * **********************************************************/ public class Fibonacci { public static void main( String[ ] args ) { // Convert the input number from a string to an integer. int number = Integer.parseInt( args[0] ); // Define first two numbers of the series. int a = 0; int b = 1; // Variable to hold the sum int sum = 0; System.out.println( "Fibonacci series = " ); System.out.print ( a + " " + b + " " ); for ( int i = 2; i < ; i++ ) { // Add the last two numbers. sum = a + b; // Shift the two numbers one place in the series. a = b; b = sum; System.out.print( + " " ); } } } |
|
|
|