Start learning free

LESSON 70 OF 501 · STRINGS - CHALLENGES

Stuttering Function in Java

Practice

Given a word word, return it said with a stutter: its first two characters, then a hyphen -, then the whole word.

 

Example 1:

Input: word = "dog"
Output: "do-dog"
Explanation: The first two characters are "do". After them come a hyphen and the whole word, "dog".

Example 2:

Input: word = "Hello"
Output: "He-Hello"
Explanation: The characters keep their case: the stutter starts with an upper-case H, as the word does.

Example 3:

Input: word = "ab"
Output: "ab-ab"
Explanation: A word with only two letters: its first two characters are the whole word.

 

Constraints:

  • word has at least 2 letters.
  • word is made of English letters only, lowercase or uppercase: no spaces, digits or punctuation.
STEP 1 OF 1
    Ctrl + Enter to check

    Stuttering Function in Java

    Keep going with Java500+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free