Quick suggestions...
xIsDivisibleByY()
: might be better to leave it asisDivisble()
, the point being it's relatively straightforward to infer the ordering.x
andy
isn't much better, since they can become misleading if you decide to rename your method argumentsa, b
ornumerator, denominator
etc.The body of
xIsDivisibleByY()
can also bereturn y != 0 && x % y == 0
.You can simply put
xIsDivisibleByY(n + n + 1, 7)
forisWow()
.Are you really expected to show your implementation for prime-checking? :D Since your upper bound is only
113
, I'm kind of tempted to just use a pre-computed list of primes and call it a day...In any case, a slight optimization for your prime-checking can be to first test if it's divisible by 2 or not. If not, you just need to iterate through the odd numbers up to
(削除)sqrtOfN
(削除ここまで)threshold
: a decidedly better name sincesqrtOfN
is never really the actual square root, is it? ;)As mentioned in @janos's @janos's answer, use a
StringBuilder
instead of rolling your ownaddToList()
method, which is also named wrongly anyways since it isn't adding to any list.boolean printDirectly
: It's commendable that you spot the slightly odd requirement of having to print toSystem.out
and returning anArrayList
. However, you should go a step to further to really illustrate how your internal method is observing this 'separation-of-concerns'-like behavior as such:// would be great to return as a List, // unfortunately caller expects an ArrayList to return itself too private static ArrayList<String> getResult(startInclusive, endInclusive) { ArrayList<String> result = new ArrayList<>(); // ... return result; } public static ArrayList<String> iterate() { ArrayList<String> result = getResult(0, 113); for (String current : result) { System.out.println(current); } return result; }
Quick suggestions...
xIsDivisibleByY()
: might be better to leave it asisDivisble()
, the point being it's relatively straightforward to infer the ordering.x
andy
isn't much better, since they can become misleading if you decide to rename your method argumentsa, b
ornumerator, denominator
etc.The body of
xIsDivisibleByY()
can also bereturn y != 0 && x % y == 0
.You can simply put
xIsDivisibleByY(n + n + 1, 7)
forisWow()
.Are you really expected to show your implementation for prime-checking? :D Since your upper bound is only
113
, I'm kind of tempted to just use a pre-computed list of primes and call it a day...In any case, a slight optimization for your prime-checking can be to first test if it's divisible by 2 or not. If not, you just need to iterate through the odd numbers up to
(削除)sqrtOfN
(削除ここまで)threshold
: a decidedly better name sincesqrtOfN
is never really the actual square root, is it? ;)As mentioned in @janos's answer, use a
StringBuilder
instead of rolling your ownaddToList()
method, which is also named wrongly anyways since it isn't adding to any list.boolean printDirectly
: It's commendable that you spot the slightly odd requirement of having to print toSystem.out
and returning anArrayList
. However, you should go a step to further to really illustrate how your internal method is observing this 'separation-of-concerns'-like behavior as such:// would be great to return as a List, // unfortunately caller expects an ArrayList to return itself too private static ArrayList<String> getResult(startInclusive, endInclusive) { ArrayList<String> result = new ArrayList<>(); // ... return result; } public static ArrayList<String> iterate() { ArrayList<String> result = getResult(0, 113); for (String current : result) { System.out.println(current); } return result; }
Quick suggestions...
xIsDivisibleByY()
: might be better to leave it asisDivisble()
, the point being it's relatively straightforward to infer the ordering.x
andy
isn't much better, since they can become misleading if you decide to rename your method argumentsa, b
ornumerator, denominator
etc.The body of
xIsDivisibleByY()
can also bereturn y != 0 && x % y == 0
.You can simply put
xIsDivisibleByY(n + n + 1, 7)
forisWow()
.Are you really expected to show your implementation for prime-checking? :D Since your upper bound is only
113
, I'm kind of tempted to just use a pre-computed list of primes and call it a day...In any case, a slight optimization for your prime-checking can be to first test if it's divisible by 2 or not. If not, you just need to iterate through the odd numbers up to
(削除)sqrtOfN
(削除ここまで)threshold
: a decidedly better name sincesqrtOfN
is never really the actual square root, is it? ;)As mentioned in @janos's answer, use a
StringBuilder
instead of rolling your ownaddToList()
method, which is also named wrongly anyways since it isn't adding to any list.boolean printDirectly
: It's commendable that you spot the slightly odd requirement of having to print toSystem.out
and returning anArrayList
. However, you should go a step to further to really illustrate how your internal method is observing this 'separation-of-concerns'-like behavior as such:// would be great to return as a List, // unfortunately caller expects an ArrayList to return itself too private static ArrayList<String> getResult(startInclusive, endInclusive) { ArrayList<String> result = new ArrayList<>(); // ... return result; } public static ArrayList<String> iterate() { ArrayList<String> result = getResult(0, 113); for (String current : result) { System.out.println(current); } return result; }
Quick suggestions...
xIsDivisibleByY()
: might be better to leave it asisDivisble()
, the point being it's relatively straightforward to infer the ordering.x
andy
isn't much better, since they can become misleading if you decide to rename your method argumentsa, b
ornumerator, denominator
etc.The body of
xIsDivisibleByY()
can also bereturn y != 0 && x % y == 0
.You can simply put
xIsDivisibleByY(n + n + 1, 7)
forisWow()
.Are you really expected to show your implementation for prime-checking? :D Since your upper bound is only
113
, I'm kind of tempted to just use a pre-computed list of primes and call it a day...In any case, a slight optimization for your prime-checking can be to first test if it's divisible by 2 or not. If not, you just need to iterate through the odd numbers up to
(削除)sqrtOfN
(削除ここまで)threshold
: a decidedly better name sincesqrtOfN
is never really the actual square root, is it? ;)As mentioned in @janos's answer, use a
StringBuilder
instead of rolling your ownaddToList()
method, which is also named wrongly anyways since it isn't adding to any list.boolean printDirectly
: It's commendable that you spot the slightly odd requirement of having to print toSystem.out
and returning anArrayList
. However, you should go a step to further to really illustrate how your internal method is observing this 'separation-of-concerns'-like behavior as such:// would be great to return as a List, // unfortunately caller expects an ArrayList to return itself too private static ArrayList<String> getResult(startInclusive, endInclusive) { ArrayList<String> result = new ArrayList<>(); // ... return result; } public static ArrayList<String> iterate() { ArrayList<String> result = getResult(0, 113); for (String current : result) { System.out.println(current); } return result; }