The java.util.Scanner is widely used for scanning inputs from the System.in object. We can easily detect an EOL with the hasNext() method of this object. When we type in the EOL, the method return false.
Here is an example:
public class masnun { public static void main(String args[]) { java.util.Scanner input = new java.util.Scanner( System.in ); System.out.println( "Press <ctrl+D> on Linux/Mac or <ctrl+Z> on Windows to exit :)" ); System.out.println( "Enter a new line: " ); while( input.hasNext() ) { System.out.println( "You typed: " ); String line = input.nextLine(); System.out.println( line ); System.out.println( "Enter a new line: " ); } } }