Problem:
We'll say a number is special if it is a multiple of 11 or if it is one more than a multiple of 11. Return true if the given non-negative number is special. Use the % "mod" operator -- see Introduction to Mod
specialEleven(22) → true
specialEleven(23) → true
specialEleven(24) → false
Solution:
public boolean specialEleven(int n) { return n % 11 == 0 || n % 11 == 1; }
I would say this should be
ReplyDeletereturn n % 11 == 0 || (n % 11 == 1 && n > 11);
Since 1 is not '1 greater than a multiple of 11'. 0 isn't a multiple of 11. CodingBat accepts 1 as a valid answer but that's not the case.
what are the || for
ReplyDeleteor symbol in java
Deleteautism
Deletepublic boolean specialEleven(int n) {
ReplyDeletereturn n % 11 <= 1;
}
public boolean specialEleven(int n) {
ReplyDeleteif(n%11 == 0 || n%11==1)
return true;
else
return false;
}
public boolean specialEleven(int n) {
ReplyDeleteint a=n%11;
if(a<2) return true;
return false;
}
return(n >= 0 && (n % 11 == 0) || (n%11 == 1));
ReplyDeletepublic boolean specialEleven(int n) {
ReplyDeleteif(n%11 == 0 || n%11==1)
return true;
else
return false;
}