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

 

srp4379@lausd.net 1-stringbasics > conCatShortestFirst
prev  |  next  |  chance

public String conCatShortestFirst(String s1, String s2)

Given TWO Strings, return their concatenation, such that the shorter one comes first.

  int len1 = s1.length();
  int len2 = s2.length();
  String s = s1 + s2; // default: s1 is shorter
  if (len2 < len1) {
    s = s2 + s1;  // if s2 is shorter!
  }
  return s;

conCatShortestFirst("ab", "c") → "cab"
conCatShortestFirst("123", "45678") → "12345678"
conCatShortestFirst("Downtown", "Magnets") → "MagnetsDowntown"

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

public String conCatShortestFirst(String s1, String s2) { }

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

Copyright Nick Parlante 2017 - privacy