Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Java, Java 7 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java, Java 7 Edition by Ivor Horton ; ISBN: 978-0-470-40414-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Java, Java 7 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2013, 05:43 AM
Registered User
 
Join Date: Jun 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ch.8 TRY IT OUT: Formatted Keyboard Input

reference pages: 323-326

I don't understand how the program knows to wait for input from user after those line of codes:

Code:
System.out.print("Enter an integer: ");
Code:
System.out.print("Enter a double value: ");
Code:
System.out.print("Enter a string: ");


does this line of code:
Code:
private StreamTokenizer tokenizer = new StreamTokenizer( new BufferedReader( new InputStreamReader(System.in) ) );
means during execution each time print method is called, the program waits for input? I drew this conclusion based on the fact that after each print method is called, the program waits for input but after each println the program execute the next instruction.
(I read in the chapter what StramTokenizer, BufferedReader, and InputStreamReader does)


here's the code snippet from the TRY IT OUT on page 325.
Code:
FormattedInput kb = new FormattedInput();
		
		for( int i = 0; i < 5; ++i ){
			try{
				System.out.print("Enter an integer: ");
				System.out.println("Ineger read:" + kb.readInt());
				System.out.print("Enter a double value: ");
				System.out.println("Double value read: " + kb.readDouble());
				System.out.print("Enter a string: ");
				System.out.println("String read: " + kb.readString());
			}
			catch(InvalidUserInputException e){
				System.out.println("InvalidUserInputException thrown.\n" + e.getMessage());
			}
		}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch. 6 - pg. 163 - Dismissing the Keyboard sirab33 BOOK: Beginning iOS 4 Application Development 1 May 26th, 2011 09:25 PM
NOT WELL FORMATTED pallone XSLT 7 June 24th, 2008 04:45 PM
Emails not formatted correctly. mcarol44 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 9 November 9th, 2007 03:53 AM
I/O streams: keyboard input kanoorani Java Basics 2 April 20th, 2007 01:58 AM
How do you get keyboard input? Polymer JSP Basics 1 October 28th, 2005 02:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.