This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes calculating values with multiple conditions. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calculating values with multiple conditions." Watch "calculating values with multiple conditions." New topic

calculating values with multiple conditions.

Rene Rad

Joined: Feb 10, 2010
Posts: 15
I'm trying to create a blackjack game and am trying to calculate the values but Ace = high or low is throwing me off. I can account for if there is 1 ace in the hand but if a second pops up my previous code couldn't handle that. I've tryed to adjust the code to use a for each loop but I can't get it working.

Below is what I have. Can anyone point me in the right direction?


Bert Wilkinson
Ranch Hand

Joined: Oct 28, 2009
Posts: 33
This method has some hope....but it's not going to work. You're looping through the deck within a loop of the you're probably getting some crazy answers on this. You need to rethink this and think about all the possible cases. What will you do if you have 2 aces in one hand?

Maybe rephrasing that question will lead you in the right direction: If you knew after going through your hand that you had 2 aces, how would that affect your summation?

good luck. And remember: You'll learn more and get better responses if you post the results of executing your code.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Or better yet, move the definition of what constitutes an "Ace" into the card itself... or even the game (consider wildcards).
I agree. Here's the link:
subject: calculating values with multiple conditions.
It's not a secret anymore!