请解释为什么17%40 = 17 [英] Please explain why 17 % 40 = 17
问题描述
我是Java的新手,实际上是一般的编程.我知道模数运算符(%)返回两个数字的余数,但是我不明白为什么17%40 = 17.
I am new to Java, actually programming in general. I understand that the modulus operator (%) returns the remainder of two numbers, however, I do not understand why 17 % 40 = 17.
我知道40%17 = 6,而17%5 = 2,而40%5 = 0.但是17%40 = 17让我感到难过.
I understand that 40 % 17 = 6, and 17 % 5 = 2, and 40 % 5 = 0. I get the gist of what value is returned as the remainder. But 17 % 40 = 17 has me stumped.
我可以设计的唯一合理化方法是,由于余数小于1,因此返回总值17,为什么不返回0?请帮我解释一下这个谜.
The only rationalization I can devise is that since the remainder is less than 1 the total value 17 is returned, why not 0? Please help to explain this enigma to me.
推荐答案
除以17/40时,商为0,余数为17.
When you divide 17/40, quotient is 0 and the remainder is 17.
取模运算符(%
)返回余数.
即
a % b = remainder of a / b
这篇关于请解释为什么17%40 = 17的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!