Question: Write a static method named oneLiner that accepts a Scanner as a parameter and returns a String, with multiple spaces reduced to a single space

Write a static method named oneLiner that accepts a Scanner as a parameter and returns a String, with multiple spaces reduced to a single space between words all on one line.

Remove all new line characters and remove all tabs.

Upload with a main method similar to below:

import java.io.*; import java.util.*; public class Chapter6 { public static void main(String[] args) throws FileNotFoundException { File file = new File("whatever.txt")); // any file will work Scanner input = new Scanner(file); System.out.println(oneLiner(input); } // method goes below here: 

For example, if input File contains the following text:

four score and seven years ago our fathers brought forth on this continent a new nation 

then oneLiner(what) should return the String:

four score and seven years ago our fathers brought forth on this continent a new nation 

Notice there is only one space between each word, all words are collapsed into a single line.

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!