Write a static method called reverseAndFlip
that takes a Scanner containing an input file as a parameter 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 the 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 it 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 original 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.