Problem:
We'll say that a number is "teen" if it is in the range 13..19 inclusive. Given 2 int values, return true if one or the other is teen, but not both.
loneTeen(13, 99) → true
loneTeen(21, 19) → true
loneTeen(13, 13) → false
Solution:
public boolean loneTeen(int a, int b) { if ((a >=13 && a <= 19) && (b < 13 || b > 19)) return true; else if ((b >=13 && b <= 19) && (a < 13 || a > 19)) return true; else return false; }
public boolean loneTeen(int a, int b) {
ReplyDeletereturn (a < 13 || a > 19) != (b < 13 || b > 19);
}
public boolean loneTeen(int a, int b) {
ReplyDeleteint count = 0;
int[] arr = new int[3];
arr[0] = a;
arr[1] = b;
for(int x = 0; x<=1; x++){
if(arr[x]>=13 && arr[x]<=19){
count++;
}
}
return count==1;
}