printlines.java

来自「java 完全探索的随书源码」· Java 代码 · 共 35 行

JAVA
35
字号
import java.io.*;// This class reads lines from standard input (System.in) and// prints each line along with its line number.public class PrintLines extends Object{  public static void main(String[] args)  {    // Set up a line number input filter to count the line numbers    LineNumberReader lineCounter = new LineNumberReader( new InputStreamReader( System.in ) );    String nextLine = null;    System.out.println( "Type any text and press return. Type 'exit' to quit the program." );    try    {      // Keep going until exit is typed      while ( (nextLine = lineCounter.readLine()).indexOf( "exit") == -1 )      {        // If readLine returns null, we've hit the end of the file        if (nextLine == null) break;        // Print out the current line number followed by the line        System.out.print(lineCounter.getLineNumber());        System.out.print(": ");        System.out.println(nextLine);      }    }    catch (Exception done)    {      done.printStackTrace();    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?