Problem:
Given a string, return a "rotated left 2" version where the first 2 chars are moved to the end. The string length will be at least 2.
left2("Hello") → "lloHe"
left2("java") → "vaja"
left2("Hi") → "Hi"
Solution:
public String left2(String str) { return str.substring(2, str.length()) + str.substring(0,2); }
public String left2(String str) {
ReplyDeletereturn str.substring(2) + str.charAt(0) + str.charAt(1);
}
how are you
Deletereturn str.substring(2) + str.substring(0,2);
ReplyDeletestr.length()?? :O