What is the remainder after dividing 13 by 5?
3
You may recall in fourth grade doing division like this:
13 / 5 == 2 with a remainder of 3.
This is because 13 == 2*5 + 3.
The symbol for finding the remainder is % (percent sign.)
If you look in the
table of operators
you will see that it has the same precedence as * and /.
class remainderExample
{
public static void main ( String[] args )
{
int quotient, remainder;
quotient = 17 / 3;
remainder = 17 % 3;
System.out.println("The quotient : " + quotient );
System.out.println("The remainder: " + remainder );
System.out.println("The original : " +
(quotient*3 + remainder) );
}
}
It would be useful to copy-and-paste this program to run it.