max1020

Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.

max1020(11, 19) ? 19
max1020(19, 11) ? 19
max1020(11, 9) ? 11

public int max1020(int a, int b) {
int temp;
if(a>b) temp=a;
else temp=b;

if (temp >= 10 && temp <= 20) return temp;
if (b >= 10 && b <= 20) return b;
if (a >= 10 && a <= 20) return a;

return 0;
}
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