1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
german
3 years ago
6

Write the method scrambleWord, which takes a given word and returns a string that contains a scrambled version of the word accor

ding to the following rules.
a. The scrambling process begins at the first letter of the word and continues from left to right.
b. If two consecutive letters consist of an "A" followed by a letter that is not an "A", then the two letters are swapped in the resulting string.
c. Once the letters in two adjacent positions have been swapped, neither of those two positions can be involved in a future swap.
The following table shows several examples of words and their scrambled versions.
word Result returned by scrambleWord(word)
"TAN" "TNA"
"ABRACADABRA" "BARCADABARA"
"WHOA" "WHOA"
"AARDVARK" "ARADVRAK"
"EGGS" "EGGS"
"A" "A"
"" ""
Computers and Technology
1 answer:
drek231 [11]3 years ago
3 0

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.

You might be interested in
What happens when two computers use the same IP address?
OLga [1]

Two computers can safely have the same IP address in certain cases. In most cases, if those two computers are on the same local network, it breaks connectivity for one or both of them. Internet protocols work by sending small, individually addressed messages. Each message can be routed differently.

I hope this helps you.

6 0
3 years ago
_____ consists of computer programs that govern the operation of a computer.
telo118 [61]
Hello <span>Siyujiang8092</span>

Answer: Software<span> consists of computer programs that govern the operation of a computer.

Hope that helps
-Chris</span>
6 0
4 years ago
What's your thoughts on people using Brainly to cheat academically?
lys-0071 [83]

Answer:

At this point, school isnt even about learning anymore. Its just about passing so you dont end up being a dropout or just a bum in general cause not everyone has the skills to make something out of nothing.

Explanation:

7 0
3 years ago
Read 2 more answers
Give 3 ways you can get creative and personal while creating a PowerPoint.
kondor19780726 [428]

Answer:

People come to listen to you – your thoughts, interpretations and insights. Fancy transitions, clips, and tons of text steal from your content and delivery.

Remember: every time you hit that clicker the audience leaves you and goes to the screen.

Explanation:

7 0
4 years ago
What does anti-malware software look for to determine that a program or a process is a virus?
Kryger [21]
Certain extensions of files. Sometimes, the name of the file could be something like Trojanx64.sys(I think). I had a few files of malware, but they were deleted. I believe the most common extension is .sys for viruses. Additionally, antivirus software could look into the properties of the program/process.
3 0
3 years ago
Other questions:
  • peter has recently bought a media player and a digital camera. he wants to buy a memory card for these devices. which memory dev
    11·1 answer
  • You install a SATA hard drive and then turn on the computer for the first time. You access BIOS/UEFI setup and see that the driv
    8·1 answer
  • In any *NIX system, after saving a script named "script_name," you need to make it executable so that you can run it. Which comm
    12·1 answer
  • Which of the following is the shortcut key combination for pasting copied text?
    11·2 answers
  • Wi-fi works by converting data signals into which of the following?
    8·2 answers
  • What does RFID use for wireless communication?<br> Infrared<br> IoT<br> Smart chip<br> Tag
    14·1 answer
  • Hosts A and B are 20 000 km away from each other. The propagation speed of the link between them is 25000 mps. The data is place
    9·1 answer
  • What considerations should you make when deciding on the size of a table?
    9·1 answer
  • LaToya is creating a program that will teach young children to type. What keyword should be used to create a loop that will prin
    9·1 answer
  • Pls help
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!