Modulus division when first number is smaller than second number

前端 未结 6 802
时光取名叫无心
时光取名叫无心 2021-01-04 00:20

I apologize if this is a simple question but I\'m having trouble grasping the concept of modulus division when the first number is smaller than the second number. For exampl

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 01:05

    First, in Java, % is the remainder (not modulo) operator, which has slightly different semantics. That said, you need to think in terms of integer-only division, as if there were no fractional values. Think of it as storing items that cannot be divided: you can store zero items of size 4 in a storage of overall capacity one. Your remaining capacity after storing the maximum number of items is one. Similarly, 13%5 is 3, as you can fit 2 complete items of size 5 in a storage of size 13, and the remaining capacity is 13 - 2*5 = 3.

提交回复
热议问题