Java Reference
In-Depth Information
This method outputs the line count and the letter count. It has three parameters: the
output stream object, the line count, and the array to output the letter count. The
definition of this method is:
writeTotal
static void writeTotal(PrintWriter outfile, int lines,
int [] letters)
{
outfile.println();
outfile.println("The number of lines = " + lines);
for ( int i = 0; i < 26; i++)
outfile.println(( char )(i + 65) + " count = "
+ letters[i]);
}
We now describe the algorithm for the method main .
1. Declare and initialize the variables.
2. Open the input and output files.
3. Read the first character.
4. while (not end of the input file):
a. Process the next line; call the method copyText .
b. Increment the line count. (Increment the variable lineCount .)
c. Read the next character.
5. Output
MAIN
ALGORITHM
9
the line count
and letter count. Call
the method
writeTotal .
6. Close the files.
COMPLETE PROGRAM LISTING
//*************************************************************
// Author: D. S. Malik
//
// Program: Line and letter count
// This program reads a given text, outputs the text as
// is, and prints the number of lines and the number of times
// each letter appears in the text. An uppercase letter and a
// lowercase letter are treated as being the same; that is,
// they are tallied together.
//**************************************************************
Search WWH ::




Custom Search