Difference:
% is the modulo operator, / is the division operator. % is the remainder operation, and / is the ordinary division sign.
Example:
System.out.println(3/5) = 0; System.out.println(2/5) = 0; System.out.println(4/5) = 0; System.out.println(6/5) = 1; System.out.println(7/5) = 1; System.out.println(8/5) = 1; System.out.println(11/5) = 2; System.out.println(12/5) = 2; System.out.println(13/5) = 2;
The result is equal to the obtained integer (the integer of the quotient)
System.out.println(17%5) = 2; System.out.println(16%5) = 1; System.out.println(13%5) = 3; System.out.println(8%5) = 3; System.out.println(7%5) = 2;
The result is equal to the remainder (how much is left)
System.out.println(2%5) = 2; System.out.println(7%8) = 7; System.out.println(6%8) = 6;
Take the remainder (take Modulo) has a rule: the left side is smaller than the right side, the result is the left side, the left side is larger than the right side, look at the remainder.
Recommended tutorial: java introductory tutorial
The above is the detailed content of The difference between '/' and '%' in java. For more information, please follow other related articles on the PHP Chinese website!