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

 

apcsaArraysConcatThreeFirstCharacters


Requires String methods: skip if you do not know about substring yet


Given an array of three Strings, return a String made up of the first character of each of the Strings, in the same order as the array.  Precondition: the input array has exactly three elements, and each String in the input array will have length() >= 1.
HINT
You could use a loop, or not. Your choice, since you know the number of array elements beforehand. Suggestion: use substring(n, n+1) to get a character out of each String.

STRINGS VS ARRAYS

Remember that Strings have length as a method, meaning a[0].length() instead of a[0].length.  This gets confusing, and people often get it wrong the other way like a.length() instead of a.length - just come back up and look at this if you get confused.  Also you can use a[0].substring()...

apcsaArraysConcatThreeFirstCharacters(["a", "b", "c"]) → "abc"
apcsaArraysConcatThreeFirstCharacters(["gl", "o", "b"]) → "gob"
apcsaArraysConcatThreeFirstCharacters(["give ", "me ", "liberty"]) → "gml"

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

public String apcsaArraysConcatThreeFirstCharacters(String[] arr) { }

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

Copyright Nick Parlante 2017 - privacy