Answered step by step
Verified Expert Solution
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
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