checkNumber, which checks the validity of its four-digit integer parameter.
/** @param n a 4-digit integer
* @return true if n is valid, false otherwise
*/
boolean checkNumber(int n)
{
int d1,d2,d3,checkDigit,nRemaining,rem;
//strip off digits
checkDigit = n % 10;
nRemaining = n / 10;
d3 = nRemaining % 10;
nRemaining /= 10;
d2 = nRemaining % 10;
nRemaining /= 10;
d1 = nRemaining % 10;
//check validity
rem = (d1 + d2 + d3) % 7;
return rem == checkDigit;
}
A program invokes method checkNumber with the statement
boolean valid = checkNumber(num);
Which of the following values of num will result in valid having a value of true?
(A) 6143
(B) 6144
(C) 6145
(D) 6146
(E) 6147