Failing a test case - Simple loop and math question.
Here is the question: Create a function, that will for a given a, b, c, do the following: Add a to itself b times. Check if the result is divisible by c. Notes: In the first step of the function, a doesn't always refer to the original a. "if the result is divisible by c", means that if you divide the result and c, you will get an integer (5, and not 4.5314). The second test is correct. ------------------------------------------------------------------------------------------------------------- My code: public class Challenge { public static boolean abcmath(int a, int b, int c) { int sum = 0; for (int i = 0; i < b; i++){ sum += a; if (sum % c == 0) return true; } return false; } } Failing this unit test and can't figure out why: @Test public void test2() { assertEquals(false, Challenge.abcmath(69, 15, 9)); } As stated in the notes, second test is correct. Passes all other 7 tests. Any thoughts? TIA!!!