Test cases
Test cases | Expected | Result |
---|---|---|
frontBack(abcd) | dbca | OK |
frontBack(Bee) | eeB | OK |
frontBack(MazE) | EazM | OK |
Java solution:
public class Program10 {
public static void main(String[] args) {
Program10.frontBack("abcd");
Program10.frontBack("Bee");
Program10.frontBack("MazE");
}
public static String frontBack(String str) {
return str.substring(str.length()-1) + str.substring(1,str.length()-1) + str.charAt(0);
}
}
Javascript solution:
const frontBack = (str) => {
return str[str.length-1] + str.substring(1, str.length-1) + str[0];
}
console.log(frontBack("abcd")); //dbca
console.log(frontBack("Bee")); //eeB
console.log(frontBack("MazE")); //EazM
Thanks, please create more question same concept to help,build logic
you will enter three “a”.