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

 

jebbert@volusia.k12.fl.us > ccc2concertRecursion
prev  |  next  |  chance

Write a RECURSIVE method that returns the total length of time a concert takes, including all of the encores. The main concert takes 'mainTime' hours. Each encore takes less time than the mainTime and less time than the previous encore, calculated recursively until the encore times are zero hours long. Each encore time is found by taking the mainTime or the previous encore time and dividing by 'divider'. For example, if mainTime=7 and divider=2, the times are calculated this way: The main concert is 7 hours long followed by a 3 hour encore (7 div 2 = 3), followed by a 1 hour encore (3 div 2 = 1), and that would be the last encore. So the total time would be 7+3+1=11 hours. In that case, return 11. The 'divider' parameter will be greater than 1. The 'mainTime' parameter will be greater than or equal to 1. You MUST use recursion to solve this problem.


ccc2concertRecursion(2, 6) → 2
ccc2concertRecursion(7, 6) → 8
ccc2concertRecursion(4, 2) → 7

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

public int ccc2concertRecursion(int mainTime, int divider) { }

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: 330

Copyright Nick Parlante 2017 - privacy