Question
Java Do Chapter 10 Exercise 11 , CopyNames : copy peoples names from an input to an output file, correcting how the names are formatted:
Java
Do Chapter 10 Exercise 11, CopyNames: copy peoples names from an input to an output file, correcting how the names are formatted:
You are given a text file containing the names of people. Every name in the file consists of a first name and last name, that is, exactly two words. Unfortunately, the programmer who created the file of names had a strange sense of humor and did not guarantee that each name was on a single line of the file.
Read this file of names and write them to a new text file, one name per line. For example, if the input file contains the lines:
Bob Jones Fred
Charles Ed
Marston
Jeff
Williams
then the output file should be:
Bob Jones
Fred Charles
Ed Marston
Jeff Williams
Hints:
You can use Scanners next method to read a single word, one at a time, from the input file.
You can assume that each name consists of exactly 2 words, and that there are only complete names in the input file.
To write out each complete name, simply read two words at a time as long as hasNext returns true and write those two words, separated by a space, to the output file.
You can ask the user for the input and output file names or read them from program command arguments.
Step 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