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]
3 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:
kramer3 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
Why is simplicity important in navigation design?
riadik2000 [5.3K]
I think it’s B.
Since it’s sometime easier to visually see something.
3 0
2 years ago
Draw the hierarchy chart and then plan the logic for a program that calculates a person’s body mass index (BMI).
dusya [7]

Explanation:

I have attached the answer as an image. I can't upload the file as it requires a licensed product and I only used demo version. I can provide the file too if you can give me your vlsig file required to use full software. However, If you just copy along the images on your Visual Studio, you will easily create the files yourself. Answer is provided for both scenarios as part A and part B, one which stops after 1 iteration and the one which loops until 0 height is given.

8 0
2 years ago
Select the correct answer.
ss7ja [257]
The answer a identifying portfolio goal
8 0
3 years ago
Read 2 more answers
In which file format is image data compiled into a binary file? TIFF SVG CGM BMP
Licemer1 [7]

BMP (Bitmap). I may be wrong. I'm sorry.

6 0
3 years ago
I need to create a method named "root positive". which will either print the square root of the number passed to it or if the nu
rjkz [21]

Answer:

Explanation:

The following code is written in Java. It is a method that calculates the square root of a number as requested. The method first checks with an IF statement if the parameter value is a positive number and then calculates the square root and prints it to the screen. Otherwise, it prints Number must not be negative. A test case has been provided in the main method and the output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter a number of type double to calculate square root:");

       double num = in.nextDouble();

       rootPositive(num);

   }

   public static void rootPositive(double num) {

       if (num > 0) {

           System.out.println(Math.sqrt(num));

       } else {

           System.out.println("Number must not be negative.");

       }

   }

}

5 0
3 years ago
Other questions:
  • How are a cell's content and format related?
    12·2 answers
  • Ujqwgydft frrhyy4e uvbw vhrwbhv vbyrewblv?
    14·1 answer
  • A circuit breaker will do which of the following
    12·1 answer
  • Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa: mild, medium, sweet,
    14·1 answer
  • Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shi
    9·1 answer
  • Is it better to try to prevent damage from natural disasters or to deal with disasters after they occur?
    10·2 answers
  • Reading (BCK FORM 2C IT 2020-2021)
    12·2 answers
  • Open excel program then use the (IF) function to fill the column of (Expensive/Cheap) then save your
    9·1 answer
  • 5. What skill is unique to reading online?
    14·1 answer
  • Suppose the cache access time is 10ns, main memory access time is 200ns, and the cache hit rate is 90%. Assuming parallel (overl
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!