Concept explainers
Explanation of Solution
Program code:
Main.java
//import the required header files
import java.io.*;
import java.util.*;
//define a class file_read_tot_sum
class Main
{
//define a method collapseSpaces()
public static void collapseSpaces(Scanner in)
{
//declare requied variables
String line, outline;
//declare the variable of Scanner class
Scanner line_in;
//iterate a while loop
while(in.hasNextLine())
{
//get the tokens
line = in.nextLine();
//new object
line_in = new Scanner(line);
//set the value for outline
outline = "";
//iterate a while loop
while (line_in.hasNext())
{
//create a new string with minimum spaces
outline += line_in.next();
//concatenate the spaces
outline += " ";
}
//print the string
System.out.println(outline);
}
}
//define the main() method
public static void main(String args[])throws FileNotFoundException
{
//create an object of Scanner
Scanner in=new Scanner (new File("Example...

Want to see the full answer?
Check out a sample textbook solution
Chapter 6 Solutions
BUILDING JAVA PROGRAMS-TEXT
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





