Created
October 23, 2015 19:16
-
-
Save Dimich7/4a065a6c424524d501a3 to your computer and use it in GitHub Desktop.
Given a string, take the first 2 chars and return the string with the 2 chars added at both the front and back, so "kitten" yields"kikittenki". If the string length is less than 2, use whatever chars are there.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test { | |
public static void main(String[] args) { | |
System.out.println(method("hi")); | |
} | |
public static String method(String str){ | |
if (str.length()<2) | |
return str+str+str; | |
String s=str.substring(0,2); | |
return s+str+s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment