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

 

jebbert@volusia.k12.fl.us > test2021_04_22_HL_stringMerge
prev  |  next  |  chance

Write a method that accepts two lower-case strings entirely made up of lower-case letters. Return a new string that merges the two strings alphabetically. The letters from the string are used in each position until a letter is found that would not be in the correct order alphabetically, then change which string letters are being pulled from. For example, with the strings "testing" and "aardvark", the first letters of the string are compared. The "a" comes alphabetically before the "t", so that "a" is used first. Now the NEXT "a" is compared to "t". It still comes first so it is the next letter used. Now we are on to the "r" in "aardvark". It is still being compared to the "t" in "testing". It STILL comes first, so it is used next. This process continues until the string "aardtestingvark" is returned. Look at the test data for additional examples. Note that the final string might NOT be in alphabetical order. Letters are pulled sequentially, but in alphabetical order. I know this could be a bit confusing. Part of the challenge is to figure out exactly what is going on. The information given above is correct, but incomplete. Here are some important rules: You may only create ONE additional string variable, which can be used to build your final result. You are allowed a maximum of ONE loop of any kind. The only string methods you may use are .charAt, .substring, .length, .equals, and .compareTo (I only used two of these!) You may not use maps or ArrayLists.


test2021_04_22_HL_stringMerge("testing", "aardvark") → "aardtestingvark"
test2021_04_22_HL_stringMerge("aardvark", "testing") → "aardtestingvark"
test2021_04_22_HL_stringMerge("stuff", "know") → "knostuffw"

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

public String test2021_04_22_HL_stringMerge(String strA, String strB) { }

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

Copyright Nick Parlante 2017 - privacy