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

For the given input String, return an output String containing only the even-indexed characters from the original, in their original sequence. This means index 0, then index 2, then index 4 etc.

Use the + operator to concatenate two Strings, as well as substring() to extract smaller Strings from larger ones. Remember that in a loop with loop control variable i, getting a one-character String out of an original String means using substring(i,i+1). As for getting even indexes, there are several ways to accomplish this but two that come to mind are adding two to a loop control variable with each pass through a loop, and using the remainder % operator. 5 % 2 is 1 because 5 is odd.

hcsStringsGimmeEvens("abcdefg") → "aceg"
hcsStringsGimmeEvens("aAaAaAa") → "aaaa"
hcsStringsGimmeEvens("AaBbCcDd") → "ABCD"

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

public String hcsStringsGimmeEvens(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: 200

Copyright Nick Parlante 2017 - privacy