Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a static method named printDuplicates that accepts as its parameter a Scan

ID: 3581395 • Letter: W

Question

Write a static method named printDuplicates that accepts as its parameter a Scanner for an input file containing a series of lines. Your method should examine each line looking for consecutive occurrences of the same token on the same line, and print each duplicated token along with how many times it appears consecutively. Non-repeated tokens are not printed. Repetition across multiple lines (such as if a line ends with a given token and the next line starts with the same token) is not considered in this problem. For example, if the input file contains the following text (sequences of duplicated tokens are underlined for emphasis): Your method would produce the following output for the preceding input file: Your code prints only the repeated tokens; the ones that appear only once in a row are not shown. Your code should place a single space between each reported duplicate token and should respect the line breaks in the original file. This is why a blank line appears in the expected output, corresponding to the fourth line of the file that did not contain any consecutively duplicated tokens You may assume that each line of the file contains at least 1 token of input.

Explanation / Answer

how*2 how*2 you*4 you*4 you*4

I*3 I*3 I*3 Jacks's*2 Jacks's*2 smirking*5 smirking*5 smirking*5 smirking*5 smirking*5

wow*2 wow*2 yippee*2 yippee*2 yippee*2 yippee*2 yippee*2 yippee*2 yippee*2 yippee*2 yay*3 yay*3

wakka*3 wakka*3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote