forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice hcs-strings > hcsStringsGimmeDoubled
prev  |  next  |  chance

Given a String str and an int n, return a one-character String containing the nth character of the input, but only when the nth character is the same as the character after it. For this problem, some of the inputs will have less than n+1 characters. If the input does not have the proper repeating characters, return an empty string. If the input has less than n+1 characters, return the entire input.

Something to remember
This is in the hint too, but it's worth remembering. The nth character of a String is actually the character with index (n-1). The first character has index 0, the second character has index 1 and so forth.

hcsStringsGimmeDoubled("Aladdin", 4) → "d"
hcsStringsGimmeDoubled("hi", 4) → "hi"
hcsStringsGimmeDoubled("moo", 2) → "o"

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

public String hcsStringsGimmeDoubled(String str, int n) { }

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: 150 Post-solution available

Copyright Nick Parlante 2017 - privacy