-1

so , as the title says i have 2 ints where if (only) one of them is between (13 , 19) , return true but if both ints are between (13 , 19) return false without using if-else Statements sry if its a lame question , still learning the ropes here

public boolean hasOnly1Teen(int age1 , int age2)
{
    boolean is1Teen = (age1 >= 13 && age1 <= 19 ) , is2Teen = (age2 >= 13 && age2 <=19);
    return (!( is1Teen == true && is2Teen == true ));
ShaDiliX
  • 45
  • 9

1 Answers1

0

Try this.

return ((is1Teen == true || is2Teen == true ) && !(is1Teen == true && is2Teen == true );

or simply use the logical xor operator.

return (is1Teen ^ is2Teen);

VHS
  • 9,534
  • 3
  • 19
  • 43
  • thanks , the instructor is so strict about not using something we have not taken during the course but its good to know that xor operator – ShaDiliX Sep 20 '17 at 16:59
  • I have given two choices. Use the one you prefer. But most importantly, try to learn how each works. – VHS Sep 20 '17 at 17:01