File history.d1 contains a brief history of computing, Computer Engineering

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();
      }
}

 

Posted Date: 3/13/2013 8:52:22 AM | Location : United States







Related Discussions:- File history.d1 contains a brief history of computing, Assignment Help, Ask Question on File history.d1 contains a brief history of computing, Get Answer, Expert's Help, File history.d1 contains a brief history of computing Discussions

Write discussion on File history.d1 contains a brief history of computing
Your posts are moderated
Related Questions
Q. Illustrate program on hypothetical machine? The program given in figure above is a hypothetical program which performs addition of numbers stored from locations 2001 onwards


Double Negation : All parents are forever correcting their children for the find of double negatives,  there we have to be very alert with them in natural language like: "He d

Q. Data Alignment in Arrays? Arrays are aligned to templates by ALIGN directive. ALIGN directive is used to align elements of various arrays with one another denoting that they

Thread is a least unit of process. In process have one or more thread.

Discuss the 5-level switching hierarchy recommended by CCITT. Hierarchical networks are able of handling heavy traffic where needed, and at similar time use minimal number of t

Assignment 3.b: Experiment with Neural Network Background: In this assignment, you will experiment with neural network for solving different types of practical problems. Y

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Control Signals from Control Bus: A number of the control signals are provided to control unit by the control bus. These signals are issued from outside the CPU.  Some of these si

Global variables are accessible only to the batch program while external variables can be referenced from any batch program residing in the similar system library.