id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

bowling


In bowling, you get two turns per frame, and you want to knock down all 10 pins in a frame. If you knock them down on the first turn, it is a strike, and you will not take the second turn in that frame. If you knock them down in 2 turns, it is a spare.

If you don't knock them all down with 2 turns, your score for that frame is the number you knocked down in the 2 turns.

If you bowl a spare in a frame, the score for the frame includes the number of pins you knock down in the first ball of the next frame.

If you bowl a strike in a frame, your score for the frame includes the pins you knock down in both turns of the next frame.

Given the number of pins knocked down in 4 turns (2 frames), calculate the score for the first frame.

a - the number of pins knocked down in the first turn
b - the number of pins knocked down in the second turn (will be 0 if a is a strike)
c - the number of pins knocked down in the third turn d - the number of pins knocked down in the fourth turn

bowling(10, 0, 10, 0) → 20
bowling(5, 5, 5, 5) → 15
bowling(4, 2, 0, 10) → 6

...Save, Compile, Run (ctrl-enter)

public int bowling(int a, int b, int c, int d){ }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200 Post-solution available

Copyright Nick Parlante 2017 - privacy