After Hannah's project, I went up to the Genius Bar with Tommy (no customers), and worked on the usual, strings and arrays.
The problem:
Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the longer string on the inside. The strings will not be the same length, but they may be empty (length 0). comboString("Hello", "hi") → "hiHellohi" comboString("hi", "Hello") → "hiHellohi" comboString("aaa", "b") → "baaab" |
public String comboString(String a, String b) {
if (a.length() < b.length())
// if a is shorter than b,
{
return a +b +a;
// then return short + long + short, or a + b+a
}
return b+a+b;
// if a is not shorter than b, then b will be shorter than a since the strings will always be different lengths.
}
I will be doing my presentation on Tuesday, so on Friday and throughout the weekend I will be working on it.
No comments:
Post a Comment