Java Reference
In-Depth Information
codeLength = console.nextInt();
//Step 3
System.out.println();
int [] codeArray = new int [codeLength];
//Step 4
readCode(codeArray);
//Step 5
compareCode(codeArray);
//Step 6
}
//Place the definition of the method readCode as
//described earlier here.
//Place the definition of the method compareCode as
//described earlier here.
}
Sample Run: (In this sample run, the user input is shaded.)
Enter the length of the code: 7
Enter the secret code: 9 2 7 8 3 5 6
Enter the length of the copy of the secret code
and a copy of the secret code:
7 9 2 7 8 3 5 6
Code Digit Code Digit Copy
9 9
2 2
7 7
8 8
3 3
5 5
6 6
Message transmitted OK.
9
PROGRAMMING EXAMPLE: Text Processing
Let's now write a program that 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.
Because there are 26 letters, we use an array of 26 elements to perform the letter
count. We also need a variable to store the line count.
The text is stored in a file, which we will call text.txt . The output will be stored in
a file, which we will call textCh.out .
Search WWH ::




Custom Search