Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you explain lnes 30 - 38, what is the return i; for and why is a -1 returned after? Can you also explain lines
Can you explain lnes 30 - 38, what is the return i; for and why is a -1 returned after? Can you also explain lines 74 - 79
D ReplacementWords.java X 1/* 2 Write a program that replaces words in a sentence. The input begins with an integer indicating the number of word replacement 3 pairs (original and replacement) that follow. The next line of input begins with an integer indicating the number of words in 4 the sentence that follows. Any word on the original list is replaced. Assume that the list will always contain less than 20 word replacement pairs. 5 6 7 8 9 Ex: If the input is: 3 automobile car manufacturer maker children kids 10 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. 11 then the output is: 12 13 The car maker recommends car seats for kids if the car doesn't already have one. 14 You can assume the original words are unique. For coding simplicity, follow each output word by a space, even the last one. 15 16 Hint: For words to replace, use two arrays: One for the original words, and the other for the replacements. 17 18 Your program must define and call the following method that returns index of word's first occurrence in wordlist. If not 19 found, the method returns -1. 20 public static int findWordInWordList(String[] wordList, String wordToFind, int numInList) 21 */ 22 23 package methods Continued; 24 25 import java.util.Scanner; 26 27 public class ReplacementWords { 28 290 public static int findWordInWordList(String[] wordList, String wordToFind, int numInList) { 30 31 for (int i = 0; i ReplacementWords [Java Application] C:\Program Files\Java\jdk-14.0.1\bin\javaw.exe (Jan 7, 2021, 7:02:41 PM - 7:02:43 PM) automobile car manufacturer maker children kids 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. The car maker recommends car seats for kids if the car doesn't already have one. 3 Writable Smart Insert 33:36: 1688 "ReplacementWords.java X 37 } 38 390 public static void main(String[] args) { // The program begins from here since this is the main method. Scanner scnr = new Scanner(System.in); 41 String[] original = new String[20]; // creating an array of 20 elements for original and modified. String [] modified = new String[20]; 40 42 43 44 45 46 47 48 49 int numInList = scnr.nextInt(); // The user is required to input a number indicating how many word pairs // will be replaced. for (int i = 0; i ReplacementWords [Java Application] C:\Program FilesVava\jdk-14.0.1\bin\javaw.exe (Jan 7, 2021, 7:02:41 PM - 7:02:43 PM) 3 automobile car manufacturer maker children kids 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. The car maker recommends car seats for kids if the car doesn't already have one. Writable Smart Insert 33:36:1688 "ReplacementWords.java X int numWords = scnr.nextInt(); // Once the for loop is done, the user is required to indicate how many words // he, she, or it will type. String[] words = new String[numWords]; // It saves the number of words as an elements for the arrays words for (int i = 0; i ReplacementWords [Java Application] C:\Program Files\Java\jdk-14.0.1\bin\javaw.exe (Jan 7, 2021, 7:02:41 PM - 7:02:43 PM) 3 automobile car manufacturer maker children kids 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. The car maker recommends car seats for kids if the car doesn't already have one. Writable Smart Insert 33:36: 1688Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started