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"
Solution:
public String comboString(String a, String b) { int lenA = a.length(); int lenB = b.length(); if (lenA > lenB) return b+a+b; else return a+b+a; }
Nice...............
ReplyDeletepublic String comboString(String a, String b) {
ReplyDeletereturn a.length() < b.length() ? a+b+a : b+a+b;
}
Perfect solution!)
DeleteNICE!
ReplyDeletepublic String comboString(String a, String b) {
ReplyDeleteString short1 = "";
String long1 = "" ;
short1 = a.length()>b.length()? b:a;
long1 = a.length()>b.length()? a:b;
return short1+long1+short1;
}
public String comboString(String a, String b) {
ReplyDeleteString short1 = "";
String long1 = "" ;
short1 = a.length()>b.length()? b:a;
long1 = a.length()>b.length()? a:b;
return short1+long1+short1;
}
public String comboString(String a, String b) {
ReplyDeleteif(a.length() > b.length()) {
return b + a + b;
}
else {
return a + b + a;
}
}
public String comboString(String a, String b)
ReplyDelete{
String str ="";
int alen=a.length();
int blen=b.length();
if(alen>blen)
{
str=b.substring(0,b.length()) + a.substring(0,a.length()) + b. substring(0,b.length());
}
else
{
str=a.substring(0,a.length()) + b.substring(0,b.length()) + a. substring(0,a.length());
}
return str;
}
Helpful
ReplyDeletepublic String comboString(String a, String b) {
ReplyDeleteint s1 = a.length(), s2= b.length();
String s3;
if (s1>s2){
s3 = b+a+b;
}else{
s3 = a+b+a;
}
return s3;
}