Question
The following algorithm represents a Black Jack player who requests additional cards, while cards are still available, until they either hit 21 or go bust.
The following algorithm represents a Black Jack player who requests additional cards, while cards are still available, until they either hit 21 or go bust. Which is the correct continuation condition for the while loop?
final Scanner input = new Scanner(System.in); final int MAX = 21; int sum = 0; while (/* TODO your choice below */) { final int cardValue = input.nextInt(); sum += cardValue; } if (sum == MAX) { System.out.println("Black Jack"); } else { System.out.println("bust"); }
- A.
input.hasNextInt() || sum < MAX
- B.
sum <= MAX
- C.
input.hasNextInt() && sum < MAX
- D.
input.hasNextInt()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started