/** * Author : Roel van Bommel * Date : 20040919 * Description: This application reads from an input stream * and outputs the result. It stops when the * token "kropsla" is encountered. * Notes : The Java class Scanner is used to read the input. */ import java.util.Scanner; public class ScanInput { public static void main( String[] args ) // Application entry point. { Scanner scanner = new Scanner( System.in ); // Scanner declaration and initialization. System.out.println( "Application started, enter text: " ); // Display welcome message. while( scanner.hasNext() ) // As long as there is still input from System.in, keep scanning. { if( scanner.hasNext( "kropsla" ) ) // If the next token equals the given text... { System.out.println( scanner.next() ); // ...output the next token of the scanner... System.out.println( "\"kropsla\" found, application stopped." ); // ...and display application ending text. System.exit( 0 ); // Finally, we exit the application. } else { System.out.println( scanner.next() ); // If the next token is not "kropsla" then only // output the next token of the scanner. } } } }