Skip to main content
Code Review

Return to Revisions

2 of 2
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/

###Naming

Your isMulThree method can be renamed to isMultipleOfThree to make the name clearer. (the same goes for isMulFive). Although these methods are really simple enough to not require any method at all. Just inline the calculation in your code.

for (int i = 1; i < input; i++) {
 if (i % 3 == 0 || i % 5 == 0) {
 sum += i; // as suggested by @tim
 }
}

###Braces

It is recommended to always use braces:

if (val == 5 || val == 0) {
 return true;
} else {
 return false;
}

Although it is even more recommended to implement it as:

return input % 5 == 0;

###Algorithm

There is a pure mathematical way of solving this problem, which removes the need for iteration completely. This algorithm is described here and here

Simon Forsberg
  • 59.7k
  • 9
  • 157
  • 311
default

AltStyle によって変換されたページ (->オリジナル) /