<p>Hello,</p>
<p>I am teaching myself CS this year. I was wondering if there are any strategies for some of the problems that will be on the test.</p>
<p>Example problem:
//Precondition: n is a 4-digit integer
//Postcondition: validity of n has been returned
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;
}</p>
<p>A program invokes method ceckNumber 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</p>
<p>How would you solve this? Manually test every option? Make a table of some sort? Write patterns?</p>
<p>I'd love to hear all details on how you would solve this type of problem. I'm not sure what the most efficient way is seeing as there is only about 3 minutes per question.</p>
<p>Thank you.</p>