1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/* Find ceiling value of a number using Math.ceil This java example shows how to find a ceiling value of a number using ceil method of Java Math class. ceil method returns the smallest interger which is not less than the value. */ public class FindCeilingExample { public static void main(String[] args) { /* * To find a ceiling value, use * static double ceil(double d) method of Math class. * * It returns a smallest integer which is not less than the argument value. */ //Returns the same value System.out.println(Math.ceil(10)); //returns a smallest integer which is not less than 10.1, i.e. 11 System.out.println(Math.ceil(10.1)); //returns a smallest integer which is not less than 5.5, i.e. 6 System.out.println(Math.ceil(5.5)); //in this case it would be -20 System.out.println(Math.ceil(-20)); //it returns -42 not -43. (-42 is grater than 42.4 :) ) System.out.println(Math.ceil(-42.4)); //returns 0 System.out.println(Math.ceil(0)); } } /* Output would be 10.0 11.0 6.0 -20.0 -42.0 0.0 */ |
Add Comment