Question: Use a single Scanner to read input. The following program counts the total number of letters in a person's first and last names. The getAndCountNameLetters()

Use a single Scanner to read input.

The following program counts the total number of letters in a person's first and last names. The getAndCountNameLetters() method creates a Scanner, reads a name from the user input, and returns the number of letters.

Run the program. Note that the program does not count letters in the last name. The first call to scnr.next() returns the first name, but also reads the last name to make future reads faster. The second call to getAndCountNameLetters() creates a different Scanner, which has nothing left to read.

Change the program by passing a Scanner to the getAndCountNameLetters() method.

Run the program again. Note that the count now includes the last name.

Use a single Scanner to read input. The following program counts the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!