In String 1 section of Java Bat there are basic string problems in which you cannot use loops to solve the problem. We should use string functions like str.length(), str.substring(i,j) etc.
Extra End Problem : Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2.
Examples:
extraEnd("Hello") → "lololo"
extraEnd("ab") → "ababab"
extraEnd("Hi") → "HiHiHi"
Solution for this JavaBat extraEnd problem:
Extra End Problem : Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string length will be at least 2.
Examples:
extraEnd("Hello") → "lololo"
extraEnd("ab") → "ababab"
extraEnd("Hi") → "HiHiHi"
Solution for this JavaBat extraEnd problem:
public String extraEnd(String str) { |