Question: Write a method called mostCommonNames that accepts a Scanner representing an input file with names on each line separated by spaces. Some names appear multiple

Write a method called mostCommonNames that accepts a Scanner representing an input file with names on each line separated by spaces. Some names appear multiple times in a row on the same line. For each line, print the most commonly occurring name. If there’s a tie, use the first name that had that many occurrences; if all names are unique, print the first name on the line. For example, if the file has this input:
Benson Eric Eric Kim Kim Kim Jenny Nancy Nancy Paul Paul Ethan Jamie Jamie Alyssa Alyssa Helene Helene Jessica Jessica

For the input above, your method should produce the following output:

Most common: Kim

Most common: Jamie

Benson Eric Eric Kim Kim Kim Jenny Nancy Nancy Paul Paul Ethan Jamie Jamie Alyssa Alyssa Helene Helene Jessica Jessica

Step by Step Solution

3.48 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static int mostCommonNames Scanner input int ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!