VI. Suppose you had already written methods (do not write them, assume you alrea
ID: 3912007 • Letter: V
Question
VI. Suppose you had already written methods (do not write them, assume you already have them): pubic static String first Word(String line) which takes a line of characters as its argument and returns a string consisting of words in the line first Word returns a string whose length is 0 (i.e, the empty string). public static String rest(String line) which takes a line of characters as its argument and returns a string consisting of everything but the first word. If there is only one word or no words at all, rest returns a string of length 0. the first word of line. If there are no Finish the code below so that it inputs a line of characters and prints each of the words in that line with a separate call to IO.outputStringAnswer: String line- IO.readString(); while (Explanation / Answer
Please note that line startig with // are comments and putted for your understanding please feel free to remove if required.
String line = IO.readString();
// running the while loop until it will be empty string
// it will be same as while(firstWord(line).length()>0)
while(firstWord(line) != ""){
//printing the first word of line using
//the firstWord method
IO.outputString(firstWord(line));
//removing the first word from line
//if only one word will left then it will return the empty string
//and above while loop will be exited
line = rest(line);
}
//Please do let me know if u have any concern..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.