Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Aug 5, 2019
  • facebook
  • twitter
  • in
  • Email

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Divide Two Positive Integers and Round Up

In Java, we can divide two positive integers and round up as follows:

int result = (x + y - 1) / y

Example: (4/3 = 1.33 and we want 2):

long result = (4 + 3 - 1) / 3; // 2
Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
w3schools.com
eloquentjavascript.net