// // Display.java: read lines of input and display them with a count // at the start of each line // import java.io.*; public class Display { public static String readNextLine(BufferedReader input) { try { String result = input.readLine(); return result; } catch ( IOException e ) { System.out.println("Unexpected read error: " + e); return null; } } public static void main(String[] args) { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int lineNumber = 0; int lines = 0; String text = readNextLine(input); while ( text != null ) { lineNumber += 1; if ( lineNumber < 10 ) System.out.println("Line 0" + lineNumber + ": " + text); else System.out.println("Line " + lineNumber + ": " + text); text = readNextLine(input); } System.out.println("*** Read " + lineNumber + " lines"); } }