top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Given two strings, append them together and return the result in Java? Conditions are ...

+2 votes

Given two strings, append them together (known as "concatenation") and return the result. However, if the concatenation creates a double-char, then omit one of the chars. If the inputs are "Mark" and "Kate" then the output should be "markate". (The output should be in lowercase).

posted Apr 15, 2017 by Prajwal C.m.

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
your questions are always making a confusion with data types.Make sure about correct ques statement and here is : if the last char of first word and first char of second word are same then omit one character.
try if(wordOne.charAt(wordOne.length()-1).toLowerCase() == wordTwo.charAt(0).toLowerCase())
print(wordOne.subString(0 to n-2).LowerCase()+wordTwo.toLowerCase())
print(wordOne.toLowerCase()+ wordTwo.toLowerCase())

1 Answer

+1 vote

Try this code

String str1; //First string
String str2; //Second string
if( str1.substring( str1.length()-1).equalsIgnoreCase( str2.substring(0,1)) )
                    System.out.println(  str1.concat( str2.substring(1, str2.length())).toLowerCase() );
                    System.out.println(  str1.concat( str2) );
answer Apr 18, 2017 by Alivia Clark
Similar Questions
+2 votes

Given 2 strings, a and b, return a string of the form shorterString+longerString+shorterString, 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). If input is "hi" and "hello", then output will be "hihellohi".

+2 votes

Given a set of random strings, write a function that returns a set that groups all the anagrams together.

Ex: star, dog, car, rats, arc - > {(star, rats), (arc,car), dog}

+2 votes

Return a version of the given string, where for every star (*) in string the star and thr chars immediately to its left and right are gone. So "ab*cd" yields "ad" and "ad**cd" also yields "ad".

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.