home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 1.2 KB | 45 lines |
- import java.io.*;
-
- /*
- * Input.class reads a line of text from standard input,
- * determines the length of the line, and prints it.
- */
-
- class Input {
- public static void main (String args[]) {
- String input = "";
- boolean error;
-
- /*
- * BufferedReader contains the readLine method.
- * Create a new instance for standard input System.in
- */
- BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
- /*
- * This loop is used to catch I/O exceptions that may occur
- */
- do {
- error = false;
- System.out.print ("Enter the string > ");
-
- /*
- * We need to flush the output - no newline at the end
- */
- System.out.flush ();
-
- try {
- input = in.readLine ();
- } catch (IOException e) {
- System.out.println (e);
- System.out.println ("An input error was caught");
- error = true;
- }
- } while (error);
-
- System.out.print ("You entered \"");
- System.out.print (input); /
- System.out.println ("\"");
- System.out.print ("The length is ");
- System.out.println (input.length ());
- } // end of main ()
-