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

 

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

Write a method that returns the number of dashes appearing at the start or end of 'str'. Only dashes at the start or end count. Do not count dashes in the middle of the string. If the string is only one character long, and that character is a dash, it only counts once. Look at the test data for examples. The ONLY string methods you are allowed to use for this problem are: .length .equals .substring (both forms) .charAt .toUpperCase .toLowerCase


quiz2021_10_21_APSLHL_findDash("-This string starts AND ends with a dash-") → 2
quiz2021_10_21_APSLHL_findDash("No dashes (-) at the start-or the end-but some in the middle") → 0
quiz2021_10_21_APSLHL_findDash("Dashes --- in the middle --- do not count!") → 0

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

public int quiz2021_10_21_APSLHL_findDash(String str) { }

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

Copyright Nick Parlante 2017 - privacy