Олимпиадный тренинг

Задача . 36013


Задача

Темы:
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);

What is the purpose of the local variable nRemaining?
(A) It is not possible to separate n into digits without the help of a temporary
variable.
(B) nRemaining prevents the parameter num from being altered.
(C) nRemaining enhances the readability of the algorithm.
(D) On exiting the method, the value of nRemaining may be reused.
(E) nRemaining is needed as the left-hand side operand for integer division.

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя