loneTeen

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

public boolean loneTeen(int a, int b) {
if((a==b)) return false;
else 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;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s