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
When creating an HTML document, what do we use to set aside space for content?
Minchanka [31]

Tags are use to set aside space for contents

<h3 /><h3>What is HTML?</h3>

HTML simply means hypertext mark-up language . This is a language for document that are design to be displayed in the web browser.

Tags are HTML codes that defines how a web browser will format and display the content.

The tags is used to set aside space to accommodate contents. Example of tags are header tags(<h1>, <h2>, <h3>, <h4>, <h5> and <h6>), paragraph tag(<p>).

learn more on HTML here: brainly.com/question/9069928

5 0
3 years ago
During the weekend, Alice often needs to access files stored on her office desktop from her home laptop. Last week, she installe
ICE Princess25 [194]

Answer:

Depending on the error message which Alice get but what could have gone wrong is perhaps firewall issue.

Explanation:

There are lots of probable reason why Alice could not access her files during the weekend but below are some common reasons:

Firewall issue: Maybe Alice has her firewall turned on unknowingly as it is known that firewall do block such types of connection except it is explicitly allowed from the firewall settings.  Another issue might be that, Alice ISP uses firewall.

FTP programs Setting: Perhaps there is a settings which Alice has not activated in the FTP program that she is using.

3 0
4 years ago
The OSHA Workplace Poster 3165 is optional for workplaces.<br> A) True<br> B) False
bezimeni [28]

Hello, your answer is ready.


Answer: A) True



Best of luck!


~

Your pal papaguy

5 0
4 years ago
Read 2 more answers
How many spaces should you use for an indent?
vladimir1956 [14]
I believe it's 5 spaces for an indent. If that's incorrect plz forgive me lol.
7 0
3 years ago
Which option will Joan use to get a glimpse of how her presentation will look when she presents it to her audience? Joan will us
Murrr4er [49]

Since Joan wants to see what her presentation would look like in the eyes of her audience, it might be best for her to use the Slideshow view that is available at the bottom right side of her desktop view.

This option is a full-screen form of her Normal view in Microsoft PowerPoint. The Slideshow view is represented by the projector screen symbol next to the zoom in and out bar.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Write an expression that will print "in high school" if the value of user_grade is between 9 and 12 (inclusive). Sample output w
    12·1 answer
  • Your marketing director at ABC Marketing Agency would like to set up an email campaign that will use personalization to referenc
    5·1 answer
  • An online journal or diary you create to share your thoughts, opinions and personal news is referred to
    13·1 answer
  • Which of the following are examples of jobs in the allied health profession? select all that apply.
    8·1 answer
  • ........ is a formal description of message formats and the rules for exchanging those messages
    12·1 answer
  • What is the result of executing the following code? You can assume the code compiles and runs. #include using namespace std; voi
    6·1 answer
  • Heeeeeeeelp :)<br> thx<br> jfdyiusjmkdsuiho;dmcvrvho;j
    5·2 answers
  • Read each question below. Then, using the drop-down menus, decide if it represents the purpose, construction, or support aspect
    11·1 answer
  • what is the arrangement of various flash elements, such as the tools panel, control panel, property inspector and stage
    12·1 answer
  • Scientist Galileo Galilei used the
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!