fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int ceil(int dividend, int divisor) {
  11. int a = dividend / divisor;
  12. int b = dividend % divisor == 0 ? 0 : 1;
  13. return a + b;
  14. }
  15.  
  16. public static int ceil2(int n, int d) {
  17. return (n + d - 1) / d;
  18. }
  19.  
  20. public static void test(int n, int d) {
  21. System.out.println((double) n / (double) d);
  22. System.out.println(ceil(n, d));
  23. System.out.println(ceil2(n, d));
  24. System.out.println(Math.ceil((double) n / (double) d));
  25. }
  26.  
  27. public static void main(String[] args) {
  28. test(-5, 3);
  29. }
  30.  
  31. }
Success #stdin #stdout 0.05s 27804KB
stdin
Standard input is empty
stdout
-1.6666666666666667
0
-1
-1.0