Java redundancy operation "%"

Source: Internet
Author: User

The two concepts of modulus operation and take-rest operation are overlapping but not identical. The main difference is that there are different operations when dividing a negative integer into a division operation.

For the number of shapes and a, the method of modulo operation or redundancy operation is:

1, to seek the integer quotient c = A/b;

2, the calculation modulus or the remainder R = a-c* B.

The modulo and take-up operations differ in the first step:

The take-rest operation rounds in the 0 direction when the C value is taken, and the modulo operation is rounded to the negative infinity direction when the C value is taken.

In each environment, the meaning of the operator% is different, C/c++,java is the remainder, and Python is the modulo

The Java rule for taking the remainder is as follows:

A%b = A-(A/b) *b

Java redundancy operation "%"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.