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

 

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

Write a method called fractionChain with parameters as shown: fractionChain(numerator, denominator, maxDenominator). This method returns a string representing the sum or difference of fractions with numerators of 1 that approximate the given fraction. Look at the sample data to try to determine exactly what this is supposed to do. Note that you continue adding or subtracting fractions until you get to one with the maxDenominator as its denominator, even if you have already reached the target sum. Also, note that if you reach the target sum and are moving off of it, you will always add the next fraction instead of subtracting it.


fractionChain(9, 11, 3) → "1/2+1/3"
fractionChain(1, 15, 4) → "1/2-1/3-1/4"
fractionChain(5, 6, 10) → "1/2+1/3+1/4-1/5-1/6+1/7-1/8+1/9-1/10"

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

public String fractionChain(int numerator, int denominator, int maxDenominator) { }

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

Copyright Nick Parlante 2017 - privacy