+ 1

2%3=2 anyone can explain

14th Oct 2021, 8:42 AM
AK 47
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.
15th Oct 2021, 8:44 AM
Emiliano Rodriguez
Emiliano Rodriguez - avatar
+ 9
3 divides 2 0(zero) times.. So, the remainder is 2...
14th Oct 2021, 8:59 AM
Indira
Indira - avatar
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.
15th Oct 2021, 8:49 AM
Emiliano Rodriguez
Emiliano Rodriguez - avatar