My code: (class name is math and it implements an interface)
public boolean isPrime(int n){
for (int i=2; i<n; i++){
if (n%i==0){
return false;
}
}
return true;
}
Assertions needed to pass:
assert math.isPrime(2);
assert math.isPrime(3);
assert math.isPrime(53);
assert !math.isPrime(55);
assert !math.isPrime(24);
assert !math.isPrime(-37337);
Oddly enough I've found that the method will pass the -37337 assertion by changing my code to:
for (int i=2; i<n; i++){
if (!(n%i==0)){
return true;
}
}
return false;
But I can't seem to figure out how to pass all of the assertions
Because it never enters the loop (2 is greater than -37337)