Wednesday, January 29, 2014

Java floor and ceiling example.

Source:
class FloorCeiling {
   public static void main(String args[]){
 
     double x = 7.5;
     double y = -8.4;    
 
     System.out.println("Math.floor(x) : " + Math.floor(x));
     System.out.println("Math.ceil(x) : " + Math.ceil(x));
 
     System.out.println("Math.floor(y) : " + Math.floor(y));
     System.out.println("Math.ceil(y) : " + Math.ceil(y));
   }
}

Output:
   $ java FloorCeiling 
   Math.floor(x) : 7.0
   Math.ceil(x) : 8.0
   Math.floor(y) : -9.0
   Math.ceil(y) : -8.0

Blog Archive