Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 6 1 5 p t s Line - Based File Processing Write a static method called reverseAndFlip that takes a Scanner containing an input
Question
LineBased File Processing
Write a static method called reverseAndFlip that takes a Scanner containing an input file as a p arameter and that writes to System.out the same file with successive pairs of lines reversed in order and with the second line of each pair reversed. For example, if the input file contains t he following:
Twas brillig and the slithy toves did gyre and gimble in the wabe.
All mimsey were the borogroves, and the mome raths outgrabe.
"Beware the Jabberwock, my son, the jaws that bite, the claws that catch,
Beware the JubJub bird and shun
the frumious bandersnatch."
The method switches the order of the first two lines, printing the second line reversed. Then i switches the order of the third and fourth lines, print the fourth line reversed. And so on It should produce this output:
ebaw eht ni elbmig dna eryg did
Twas brillig and the slithy toves
ebargtuo shtar emom eht dna
All mimsey were the borogroves,
nos ym kcowrebbaJ eht eraweB"
nuhs dna drib bujbuj eht eraweB
the jaws that bite, the claws that catch,
the frumious bandersnatch."
Notice that a line can be blank, as in the third pair. Also notice that an input file can have an odd number of lines, as in the one above, in which case the last line is printed in its origi nal position. You may not make any assumptions about how many lines are in the Scanner and you may not construct any extra data structures to solve this problem.
Write your code below:
Edit View Insert Format Tools Table
pt Paragraph
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