BlackJack I
Collapse Content
Show Content
You're writing a program to play a BlackJack variety and need to write a method to handle the score.
In general, given two numbers, a
and b
, return their sum. However, if the sum is greater than 21
, return 0
instead (since the player has "gone bust").
Image from Wikipedia
Challenge
Return the score of two blackjack 'cards', as described above. (The numbers can be from 1-13).
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
thales
Jul 15, 12:01 PMhow can this be wrong?
thales
Jul 15, 12:04 PMsolved it, it was just a bracket to much ( luckely not a bridge to far :-))
Indrajith Karunarathne
Feb 1, 2:17 AMSolved, It's really Easy.
static int doStuff(int a, int b){
int sum = a + b;
if (sum>21){
return 0;
}else{
return sum;
}
}
Adonay
Aug 14, 2:03 AMyou can do it in a single line ex
return (a+b > 21)? 0 : a+b; // just like that.
Hanlise
May 6, 8:07 AMsum1= a+b
if sum1 > 21:
return 0
else:
return sum1
using python it should works