We know that an int variable, x, has been declared
It has been assigned a non-negative value
We need to write an expression that extracts the rightmost digit of x
The logic for doing so would be to divide the number by 10, and checking the remainder. The remainder will always yield the rightmost digit. In case the number is a multiple of 10 then the remainder would be 0 (which would be the rightmost digit of the number)
So we can do so by:
int y = x % 10;
% is the modulo function, which returns the remainder after carrying out division
we have declared y to be int, as % will always return int values.