简体   繁体   English

Java模数概念-算术定义(a / b)* b +(a%b)

[英]Java modulus concept - arithmetic definition (a/b)*b+(a%b)

I have recently started learning code (Java), and have looked up the modulus operator on the Oracle website, as per the section 15.17.3. 我最近开始学习代码(Java),并按照15.17.3节的要求在Oracle网站上查询了模运算符。 of the following link: 以下链接:

http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.17.3 http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.17.3

Basically, if a is the denominator, and b is the nominator, it states that: (a/b) * b + (a%b) = a , which defines the modulus operator as: a%b = a – (a/b) * b . 基本上,如果a是分母, b是分母,则表明: (a/b) * b + (a%b) = a ,将模运算符定义为: a%b = a – (a/b) * b

I am confused because the equation simply does not work, which can be simplified as a%b = 0 . 我很困惑,因为该方程式根本不起作用,可以将其简化为a%b = 0 I know my basic math algebra, so I am hoping if someone can enlighten me on how is it supposed to equal? 我知道我的基本数学代数,所以我希望有人能启发我理解它的相等性吗?

For integers, operator / means integral division, not mathematical one, for example: 对于整数,运算符/表示整数除法,而不是数学除法,例如:

7/2 = 3
6/2 = 3
5/2 = 2
4/2 = 2
3/2 = 1
2/2 = 1
1/2 = 0

In math terms, formula from java spec will be written like: 用数学术语来说,来自Java规范的公式将写为:

⌊a/b⌋ * b + (a%b) = a
a%b = a – ⌊a/b⌋ * b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM