/* 9/5/2019
 * This example source code demonstrates the use of  
 * random() method of Math class
 * Generating a 
 * random number from 1 to 10
 * also, Math.round() and example of forced conversion
 * long data type
 */

public class RandomNum{

 public static void main(String[] args) {
   
  // define the range
  int max = 10;
  int min = 1;
  int range = max - min + 1;   
  
  // generate random number from 1 to 10
  int rand = (int) (Math.random()* range) + min;
  System.out.println("Random number is " + rand);
  
  int x = (int) 10.7; // forced conversion from double to int, without this we
                      // got a Type Mismatch compiler error
  System.out.println("10.7 truncated is " + x);
  long y = Math.round(10.7);
  System.out.println("10.7 rounded is " + y);  
  
  y = 100000000000L;
  System.out.println("y is " + y);
 }
}






