File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Divisibity Test Question

 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, my C++ compiler is on my Office machine not Java (java is on other computers) so the code below is in C++ but the question I have is relevent in Java as well...

Divisibility test here 3 & 9



Now it works just fine however, my student are doing this (Getting the same answers)



Question:

1. Why do I see books use the first solution when the second is shorter and give the same answer.
2. What is the point of all of those "tests" when the second solution appears to always work.
3. Were would the second solution fail? I want them to do the first solution not the second...

Move to appropriate forum if needed. jc
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it may depend on the exact wording of the problem. it's well known that if a number is divisible by 3, if you add up all the digits, that too will be divisible by 3. The same applies for 9. It looks to me like the first solution is a code representation of this.

if the original problem said "If a number is divisible by 3, then... Write some code to do this and print if the number is divisible by 3 and 9", then you'd have to have something like your first example.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic