Problem:
Return true if the given non-negative number is a multiple of 3 or 5, but not both. Use the % "mod" operator -- see Introduction to Mod
old35(3) → true
old35(10) → true
old35(15) → false
Solution:
public boolean old35(int n) { return n % 3 == 0 ^ n % 5 == 0; }
What’s is ^
ReplyDeleteXor
Delete^ is a Xor logical operator
ReplyDeleteWhy we r using that and when we use xor
Deletepublic boolean old35(int n) {
ReplyDeletereturn (n % 3 == 0) != (n % 5 == 0);
}
public boolean old35(int n) {
ReplyDeletereturn (n%3==0&&n%5!=0)||(n%3!=0&&n%5==0);
}
public boolean old35(int n) {
ReplyDeleteif(n%3 ==0 && n%5 ==0){
return false;
}else if(n%3 ==0 || n%5 ==0){
return true;
}else{
return false;
}
}