+ 1
2%3=2 anyone can explain
4 Answers
+ 1
For type int, 3 goes into 2, 0 times. So 2 / 3 = 0 , and the remainder is discarded. The modulu (%) finds that remainder. In this case 2 % 3 = 2 because 2 is the remainder.
In the same way, 10 / 8 = 1, because 8 goes into 10 one time. And 10 % 8 = 2, because there is a remainder of 2 after 8 goes into 10 one time.
+ 9
3 divides 2 0(zero) times..
So, the remainder is 2...
0
% is used alot to find values with specific dividends. For example, you can identify if a value is even by stating
If(x % 2 == 0)
System.out.print(x + â is evenâ);
Because even numbers will have no remainder when divided by 2, and this condition will be true; whereas odd numbers will habe a remainder when dividing by 2, and so this condition will not be met.