How to round up the result of integer division in Java

1 Answer

0 votes
public class Main {
    public static void main(String args[]) {
        int a = 247, b = 9;
         
        double result = (double)a / b;
        int result_round_up = (int)Math.ceil((double)a / b);
  
        System.out.println(result);
        System.out.println(result_round_up);
    }
}
 
 
 
 
/*
run:
  
27.444444444444443
28
  
*/

 



answered Aug 18, 2021 by avibootz
edited Dec 4, 2024 by avibootz

Related questions

1 answer 121 views
1 answer 108 views
1 answer 131 views
1 answer 159 views
1 answer 89 views
1 answer 156 views
1 answer 159 views
...