file historyd1 contains a brief history of


File History.d1 contains a brief history of computing. There are no indentations in this file. Write a program to read this file, inserting five blank spaces at the beginning of each paragraph. You can recognize a paragraph because a blank line appears before the first line of each paragraph. Write the changed file on History.d2. In the program documentation, described the loop(s) used as count - controlled or event -controlled.

  • Use the following loop as a model:

// Application IOLoop counts the number of blanks per line
// and the number of lines in a file
import java.io.*;
import java.util.Scanner;
public class IOLoop
{
      public static Scanner inFile;
      public static PrintWriter outFile;
 public static void main(String[] args) throws IOException
      {
        int lineCount = 0;
        int blankCount;
        int index;
        String inputString;
        inFile = new Scanner(new FileReader("history.dat"));
        outFile = new PrintWriter(new FileWriter("data.out"));
    while (inFile.hasNextLine())
        {
     inputString = inFile.nextLine();
          lineCount++;
          blankCount = 0;
          index = inputString.indexOf(' ');
          while (index != -1)
          {
            blankCount++;
            if (inputString.length() != 1)
            {
              inputString = inputString.substring(index+1,
                inputString.length());
              index = inputString.indexOf(' ');
            }
            else index = -1;
          }
          outFile.println("Line " + lineCount + " contains "
            + blankCount + " blanks.");
        }
        outFile.close();
        inFile.close();
      }
}

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: file historyd1 contains a brief history of
Reference No:- TGS0210772

Expected delivery within 24 Hours