Units of a number and if over by 1 it counts as two? -



Units of a number and if over by 1 it counts as two? -

i new programming using java , can't utilize fancy solve this. assume simple math can't seem figure out.

i need determine how many units of 25 (in miles) bundle beingness shipped (remember parts of 25 count total 25, 75 3 units of 25 while 76 4 units of 25).

so how do math find out how many units number user enters be. 25.

i tried partition wont give me 2 units if miles / 25.

please help!

edit

i have found online using (miles + 24) / 25;

but not understand that...

you round it. computer languages have means of rounding integers.

many languages today have mod operator (often % sign) returns remainder after division.

so, can utilize

(1) int wholeunits = miles / 25; (2) remainder = miles % 25; (3) if (remainder != 0) wholeunits = wholeunits +1;

so, (1) determines number of whole units -- 75 homecoming 3, 74 homecoming 2, , 76 homecoming 3.

(2) give remainder when dividing 25. so, 75 % 25 = 0. 76 % 25 = 1. , 74 % 25 = 24.

(3) if remainder other zero, need add together 1 wholeunits. so, 75 have 0 remainder 3. 74 homecoming 24, , you'd add together 1 2 have, getting 3 whole units. , 76 homecoming (3+1) = 4.

so, there different ways of doing it, depending on language you're using. easiest thing figure out round function , utilize it. can long way these 3 steps if prefer.

units-of-measurement

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -