If you exchange 372 pennies for dollar bills, how many bills do you get? How many pennies are left over?

A good answer might be:


Practice with Remainder Operator

For positive numbers,   INT % X   means to fit as many X's as you can into INT, and then the left over amount is the value of the expression. Try that with the following:

Expression ResultExpression Result
7 3 7 5
10 5 10 6
129 100 1999 100
17 2 18 2

QUESTION 13:

Say that your program needs to test if a variable   val   is odd or even:

int x = ...... ;

if ( ___________________ )

  System.out.println( x + " Is even " );
else
  System.out.println( x + " Is odd " );

Fill in the blank so the fragment works.