about | help | code help+videos | done | prefs |
Write a method that calculates the "total" of a string. The "total" is found by starting at zero, then adding one to the total each time a "+" appears in the string and subtracting one from the total each time a "-" appears in the string. However, if there is a "0" (zero) in the string, that resets the total to zero at that point then continues as above. For example the "total" of "+++-+0+0+-+-+++" is 1. The running total gets up to 3 before the first "0" resets the total to zero. Then the running total goes back up to 1 only to get reset to zero again. Then after that last zero the running total gets back up to 3, so a value of 3 is returned. If the string contains any characters besides "-", "+", and "0" just ignore those characters. The only string methods you are allowed to use are .length, .charAt, .substring, .equals, and .compareTo. dec9_2016_APSLHL_total("+") → 1 dec9_2016_APSLHL_total("-") → -1 dec9_2016_APSLHL_total("") → 0 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 220
Copyright Nick Parlante 2017 - privacy