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
AVprozaik [17]
4 years ago
13

Write a program that replaces words in a sentence. The input begins with an integer indicating the number of word replacement pa

irs (original and replacement) that follow. The next line of input begins with an integer indicating the number of words in the sentence that follows. Any word on the original list is replaced. Ex: If the input is: 3 automobile car manufacturer maker children kids 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. then the output is: The car maker recommends car seats for kids if the car doesn't already have one. You can assume the original words are unique. For coding simplicity, follow each output word by a space, even the last one. Hint: For words to replace, use two vectors: One for the original words, and the other for the replacements. Your program must define and call the following function that returns index of word's first occurrence in wordList. If not found, then the function returns -1. int FindWordInWordList(vector wordList, string wordToFind)
Computers and Technology
1 answer:
kramer4 years ago
3 0

Answer: provided in the explanation segment

Explanation:

This is the code to run the program:

CODE:  

//Input: 3 automobile car manufacturer maker children kids

  //15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one.

  import java.util.Scanner;

  public class LabProgram{

  public static int findWordInWordList(String[] wordList, String wordToFind, int numInList) {

          for (int i = 0; i < numInList; i++) {

              if (wordList[i].equals(wordToFind)) {

                  return i;

              }

          }

          return -1;

      }

      public static void main(String[] args) {

          Scanner scan = new Scanner(System.in);

          String[] original_String = new String[20];

              String[] modified_String = new String[20];

          int numInList = scan.nextInt();

          for (int i = 0; i < numInList; i++) {

              original_String[i] = scan.next();

              modified_String[i] = scan.next();

          }

          int num_Of_Words = scan.nextInt();

          String[] words_To_Replace = new String[num_Of_Words];

          for (int i = 0; i < num_Of_Words; i++) {

              words_To_Replace[i] = scan.next();

          }

          int indx;

          for (int i = 0; i < num_Of_Words; i++) {

              indx = findWordInWordList(original_String, words_To_Replace[i], numInList);

              if (indx != -1)

                  words_To_Replace[i] = modified_String[indx];

          }

          for (int i = 0; i < num_Of_Words; i++)

              System.out.print(words_To_Replace[i] + " ");

          System.out.println();

      scan.close();

      }

  }

cheers i hope this helps!!!!1

You might be interested in
Hey can someone help?
Zinaida [17]
Send an email to it!
4 0
3 years ago
Read 2 more answers
What are some useful applications of video games?
vekshin1

Answer:

Steam, Origin, Uplay and epic games

Explanation:

8 0
3 years ago
What name is given to the assurance that requested information is available to authorized users upon request
mrs_skeptik [129]

Answer:

Availability

Explanation:

With Data availability, it means that we are saying that information is accessible to users. This gives the assurance of the system and also the data being accessible to authenticated users anytime they have the need for it.

It is simply saying that information would be operable by users with authorization whenever they request to.

5 0
3 years ago
Now, we’re ready to program! Leave the visualizer and go back to https://repl.it/ to write your program. Here is the pseudocode
svlad2 [7]

Answer:

here

Explanation:

6 0
3 years ago
1) All the elements of an array in Java MUST conform to the same data type.
Ostrovityanka [42]

Answer:

TRUE

Explanation:

The array is allow to store the multiple values but with same data type.

It cannot store element with different data type.

For example:

int array[] = {1, 'b', 8.7, 9, 'z'}

the above is wrong way to declare the array.

the correct ways is:

int array[] = {1,2,3,4};

float array[] = {1.2, 3.4, 9.6};

we can store only same data type element in multiple tiles.

6 0
4 years ago
Read 2 more answers
Other questions:
  • Which of the following statements is false? a. Racks and bins are examples of storage equipment. b. Automation refers to equipme
    9·1 answer
  • Being able to download a chapter of a new book before buying it, or listening to a few seconds of a song before purchasing it ar
    7·1 answer
  • The formatting option functions like space bar. However instead of moving one space at a time, it allows you to move your text i
    7·1 answer
  • What statement best describes what a circle graph shows
    13·1 answer
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • __ allow(s) users with mobility issues to control the computer with their voice.
    6·2 answers
  • Hannah wanted to watch a movie. She typed the movie name on the search engine. In result she found the downloadable link of the
    10·1 answer
  • Terrell, a programmer, is creating a website for an online merchant and wants the program to calculate the total price based on
    14·2 answers
  • What are some potential challenges that society will face given the digital revolution? You may want to think particularly of th
    10·1 answer
  • 2. The Warren Commission investigated the assassination of President _______________________ in 1964.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!