Answer:
Let's implement the program using JAVA code.
import java.util.*;
import java.util.ArrayList;
import java.io.*;
public class ScrambledStrings
{
/** Scrambles a given word.
* atparam word the word to be scrambled
* atreturn the scrambled word (possibly equal to word)
* Precondition: word is either an empty string or contains only uppercase letters.
* Postcondition: the string returned was created from word as follows:
* - the word was scrambled, beginning at the first letter and continuing from left to right
* - two consecutive letters consisting of "A" followed by a letter that was not "A" were swapped
* - letters were swapped at most once
*/
public static String scrambleWord(String word)
{
// iterating through each character
for(int i=0;i<word.length()-1;)
{
//if the condition matches
if(word.charAt(i)=='A' && word.charAt(i+1)!='A'){
//swapping the characters
word=word.substring(0,i)+word.charAt(i+1)+word.charAt(i)+word.substring(i+2);
//skipping the letter
i+=1;
}
//skipping the letter
i+=1;
}
return word;
}
Explanation:
Note: Please replace the "at" on the third and fourth line with at symbol that is shift 2.