Questions about the divisor, divisor, quotient, and remainder in programming

Source: Internet
Author: User

Examples are as follows:

Class test{

System.out.println ("1/10=" +1/10);

System.out.println ("1%10=" +1%10);

System.out.println ("2/10=" +2/10);

System.out.println ("2%10=" +2%10);

}

The results are as follows

1/10= 0

1%10= 1

2/10= 0

2%10= 2

Self-summary analysis: In programming if "dividend" is less than "divisor", "quotient" (that is,/) is all 0, "remainder" (that is,%) is "dividend".

A programming problem that extends from this

public class Test {

public static void Main (string[] args) {


int i = 0;
while (true) {
i = (i+1)%10;//divisor is 10, the remainder will never exceed 10, so the output number will always be less than 10.
System.out.println (i);
}

}

}

This is a programming question with an infinite output of 10 or less digits.

Because the divisor is 10, so no matter how much I grow, the rest of the number is not more than 10, so the result is always controlled between 0-9.

Examples are as follows: I =10, i%10=0;

i=23,i%10=3;

i=36,i%10=6;

I=100023,i%10= 3;

No matter how big the dividend, the remaining number is the number on the rightmost single digit in the quotient.

Like 1/10, it's 01,2/10, it's 02.

10/10 the above is 10 bits for a bit 0, so the quotient is 0

32/10, above 10 bit is 3, digit is 2, therefore 32%10=2;

Never find out why this is to be calculated, just do a little analysis according to the rules, busy record down.

If someone finds a mistake, make sure to leave a message.

Questions about the divisor, divisor, quotient, and remainder in programming

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.