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
Home » 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
At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.
See our full editorial policy.