I am working on the following problem from codingbat:
Given 2 int values โโgreater than 0, return any value closest to 21 without going over. Return 0 if they both go over.
blackjack (19, 21) โ 21
blackjack (21, 19) โ 21
blackjack (19, 22) โ 19
My solutions:
public int blackjack(int a, int b) { if (a>21){ if (b>21){ return 0; } return b; } else if(b>21) return a; return Math.max(a,b); }
Is there anything in my logic that can be improved to make it more efficient? Am I doing something unnecessary?
source share