How do you make an if-then statement return a greater value?

From ggc

Jump to: navigation, search

I'm working on the Logic problem, blackjack. It says to return the value nearest 21. How can you make it return a value nearest 21? Here's what I have but it doesn't work.

public int blackjack(int a, int b) {

 if(a>21 && b>21)
  {
   return 0;
  }
 else if(a<=21 && a>b)
  {
   return a;
  }
 else if(b<=21 && b>a)
  {
   return b;
  }
 else
  {
   return 0;
  }

}

What if both a and b are 21? or if they are both the same?





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter