Problem:
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
Solution:
public int max1020(int a, int b) { int OUTPUT =0; if (a >= 10 && b <=20) { if (a > b )OUTPUT = a; else if (b > a) OUTPUT = b; } // (10 <= a <= 20) and (b > 20 or b < 10) return a; //( a > 20 or a < 20) and (10<=b <=20 return b; if ( (10 <= a && a <=20) && (b>20 || b < 10) ) OUTPUT = a; if ( ( a > 20 || a <10) && (10 <=b && b <= 20) ) OUTPUT = b; return OUTPUT; }
No comments :
Post a Comment