I'm taking an AP Computer Science course and have a brief question about the purpose of a particular variable in Java program. Below is my own slight adaption of a certain program in my textbook...
public class Nineteen {
public static void main(String[] args) {
int valid = checkNumber(6145);
}
public static int checkNumber(int n)
{
int d1,d2,d3,checkDigit,nRemaining,rem;
checkDigit = n % 10;
nRemaining = n / 10;
d3 = nRemaining % 10;
nRemaining /= 10;
d2 = nRemaining % 10;
nRemaining /= 10;
d1 = nRemaining % 10;
rem = (d1 + d2 + d3) % 7;
System.out.println("checkNumber executed.");
if (rem == checkDigit) {
System.out.println("Equal");
}
return 1;
}
}
My book says the purpose of nRemaining
in this program above is to enhance the readability of the program, not to be used as a left-hand operand for integer division. Can anyone help explain why this is? I'm certain the program can be rewritten in a more condensed way, but is that the most obvious purpose of it?