I am doing the following home exercise:
Given 2 int values ββgreater than 0, return any value closest to 21 not passing. Return 0 if they both go over.
I made the code below:
public static void main(String[] args) {
System.out.println(blackjack(22,22));
System.out.println(blackjack(25,25));
System.out.println(blackjack(19,25));
System.out.println(blackjack(25,19));
System.out.println(blackjack(10,10));
System.out.println(blackjack(19,10));
System.out.println(blackjack(1,19));
}
public static int blackjack(int a, int b) {
if (a > 21 && b > 21) {
return 0;
}
else if (a <= 21 || b > 21) {
return a;
}
else if (a > 21 || b <= 21) {
return b;
}
else if (a >= b) {
return a;
}
else {
return b;
}
}
All this works, except for the last line of output in my main. I keep getting "a" or "1" in this case, so I'm not sure what is wrong with my last line in the method declaration. I feel that something is wrong, but I'm not sure what to change.
source
share