<p>I'm just wondering how this question would be scored. Coding bat gives you some suggestions on how to solve it, but I didn't really use it. Would I get counted off? My solution works fine, but I think they're looking for something different.<br>
Question
Given a positive int n, return true if it contains a 1 digit. Note: use % to get the rightmost digit, and / to discard the rightmost digit. </p>
<p>hasOne(10) → true
hasOne(22) → false
hasOne(220) → false</p>
<p>Solution
public boolean hasOne(int n) {
String test= "" + n;
return test.contains("1");
}</p>
<p>Bump. I guess my real question is what do ap scorers think about overly simple solutions?</p>
<p>I’m fairly certain that AP Comp Sci questions won’t be structured this way. When I took the exam, the questions were more practical and object-oriented, rather than some random mathematical function.
Specifically, your solution, though technically “correct,” is not answering what the question is testing. AP exam questions have essentially one “best” answer that they are trying to lead you toward, but any variation up to a reasonable degree will probably be accepted. Your “creative” solution would not likely be accepted, as the question tells you to use modulus division to get the right answer (not to mention that your solution is rather inefficient). Note that on the AP exam, you will use pencil and paper, and your code will be scored by humans, not by machines. Your answer misses the point, so it would not likely earn many points.
See [AP</a> Central - The AP Computer Science A Exam](<a href=“Supporting Students from Day One to Exam Day – AP Central | College Board”>AP Computer Science A Exam – AP Central | College Board) for some released sample FRQs more in line with what the CollegeBoard is testing.</p>
<p>Let me answer this slightly differently than @some11no.</p>
<p>The principle rule we use in scoring is: if it works, it’s eligible for full credit. The only reason a solution might not be eligible for full credit is if the problem description explicitly tells you to do it one way, or explicitly forbids you from doing it another way. </p>
<p>There isn’t necessarily a “best answer” for each problem. The published exams have “canonical solutions”, which are ideal in terms of elegance, length, and function. We publish those so that students and teachers can see examples of good solutions. But an inelegant solution that works is just fine.</p>
<p>So … your one-line solution above would be fine (depending on how you interpret the “note”). But typically, the exam writers develop questions that don’t have such simple solutions, so that there’s a chance for you to show your algorithm development skills.</p>