Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

Define evaluation and explain its role in HRD

Answered: 1 week ago

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago