+ 2

public class Program { public static void main(String[] args) { int x=8, y=2; System.out.println(y%x);

can anyone explain how the output of this code is 2?

30th Dec 2019, 4:32 PM
BAYODE BLESSING AKINBOLA
3 odpowiedzi
+ 2
% gives the remainder of a division. 8%5 is 3, because 5 fits one time into 8, and then 3 will be left. 2%8: 8 fits zero times into 2, and 2 will be left over.
30th Dec 2019, 4:42 PM
HonFu
HonFu - avatar
+ 2
Read about the modulo operator. https://www.sololearn.com/learn/Java/2140/
30th Dec 2019, 4:43 PM
Avinesh
Avinesh - avatar
+ 2
Thanks guys
30th Dec 2019, 4:47 PM
BAYODE BLESSING AKINBOLA