APCS Strategies?

<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>

<p>For these types of questions understanding how the method works is important. And I seen this in the Barrons prep book (I finished studying APCS for this year’s exam).</p>

<p>What checkDigit does is to take the ones digit from the number n.
nRemaining takes the 3 digits starting from the left.
d1 - d3 takes all other individual digits. All those up and find the remainder when divided by 7.</p>

<p>So for answer a) you have checkDigit = 3, d3 = 4, d2 = 1, d1 = 6
6+1+4 =11 %7 = 4 but is != 3 so false</p>

<p>I hope that helps. Search CC for more tips.</p>