Generation

generate functionFri, 18 Nov 2022

iven a string made up of letters a, b and c, switch the position of letters a and b (change a to b and vice versa). Leave any occurrence of c untouched. Return the resultant string. (Source: Codewars) Hint: Use string.replace(char oldCharacter, char newCharacter) to replace one character with another. Hint: If you directly switch the first letter with the second letter, you lose track of all original occurrences of the second letter (which you needed to switch also). Think of a logic to use a placeholder character (other than a, b and c) to start with and switch it later. Sample Input 1 acb Sample Output 1 bca

public String replace(String word){ // Write your code below return word; }

Want to kickstart your project?Use the new AI Studio to create your code