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

 

orion.a.smith@gmail.com hcs-strings > apcsaStringsGimmeDoubled
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.

HINTS
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. Use substring() with two parameters or charAt() to extract characters from a String. You will probably need to use length() and maybe also equals(). Remember that the nth character has index n-1.

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

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

public String apcsaStringsGimmeDoubled(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

Copyright Nick Parlante 2017 - privacy