2

this is the code fragment. I'm not too sure what num%2 is though. % would give the remainder, so does that mean that the remainder of num must be 2?

int num = 1, max = 20;
while (num < max)
{
     if (num%2 == 0)
          System.out.println(num);
     num++;
}
studentS
  • 41
  • 1
  • 1
  • 5

1 Answers1

3
num%2==0

means the remainder of num divided by two which if something is divided by two the only remainder it could have is either 0 or 1, so its taking the remainder of dividing num by 2 and checking if it is equal to 0

JRowan
  • 6,824
  • 8
  • 40
  • 59