Due: Monday, 18 May 2009 (midnight)
R1C1 R3C1 R1C3 R299999999C26 R52C52 R53C17576 R53C17602 R0C0The corresponding output for the sample input above is:
A1 A3 C1 Z299999999 AZ52 YYZ53 YZZ53
java Excel < dataNow the characters found in the standard input come from the file named data. When the standard input comes from the keyboard a signal of some kind is needed to indicate from the interactive user when the end-of-file is reached because the length of the "file" cannot be known in advance. This signal is understood by the operating system which then passes it to the program. Different operating systems provide different mechanisms for doing this. In Unix the usual signal is typing control-D (in Dos, control-Z) on a line by itself. (Typing control-D in the middle of the line may have the effect of putting the u0004 character in the input stream instead of signaling end-of-file.)
The standard output is the stream of characters that the Java program writes to the PrintStream called System.out. The standard output is associated with the computer display by default, but can be associated with the file as in
java Excel > outputNow the output is collected in the file named output. Since keystrokes are echoed on the display, it is sometimes hard for the user to distinguish which characters on the display correspond to the standard input and which characters to the standard output. From the point of view of the program no such confusion exists.
Using standard input and standard output for IO is very flexible. The user of the program (instead of the program writer) can decide whether to type in the input or put the input in a some file. If the program was written to take input from a particular file, the user of the program has no choice.
final Scanner s = new Scanner (new BufferedInputStream (System.in));
while (s.hasNextLine()) {
final String line = s.nextLine();
System.out.println (line);
}
It will be necessary to include:
import java.util.Scanner; import java.io.BufferedInputStream;
To read a number of integers (delimited by white space) do:
final Scanner s = new Scanner (new BufferedInputStream (System.in));
while (s.hasNextInt()) {
final int n = s.nextInt();
System.out.println (n);
}
If the input has a sentenal value do:
final Scanner s = new Scanner (new BufferedInputStream (System.in));
for (;;) {
final int n = s.nextInt();
if (n==0) break;
System.out.println (n);
}
Using regular expressions it is possible to change the delimiters used by the scanner class:
final Scanner s = new Scanner (new BufferedInputStream (System.in).useDelimiter ("[RC\\s]+");
This makes any sequence of white space characters, R's, or C's, a delimiter.
Turn in the Java source code for the program using the submission server. The file name should be Excel.java and the project is asgn01. Be sure your name is in comments at the beginning of your program as required in the standard header for this class. For your convenience, here is a submission form for this assignment.
|
Course=cse2010 Project=asgn01 |