//This illustrates examples of overflow and underflow (loss of precision)
class Precision {
  public static void main(String [] args) {
    //overflow examples
    
    //the line below gives a compiler error
    //int x = 9999999999; 
    
    //but these two don't (one less '9' in each)
    int x = 999999999;
    int y = 999999999;
    int z = 999999999;
    
    //print the product (clearly too big..)
    int prod = x * y * z;
    System.out.println(prod);  //prints -1532731905 : OVERFLOW!
    
    //============================================================================//
    
    //loss of precision example
    double d1 = 4.35 * 100;
    System.out.println(d1); //prints 434.99999999999994
    
    //You can compare doubles for equality (it compiles--correction), but it may not be
    //what you want.  
    double a = 4.35 * 100;
    double b = 435;
    if(a == b) {
      System.out.println("They are equal!"); //this won't be executed...
    }    
    //rather than compare doubles for equality, we compare them to within a small margin
  }
}
