GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing syntaxdb.com — User Input in Java - SyntaxDB - Java Syntax Reference
LanguageVersion: SE 8Categories
User Program CommunicationUser Input in JavaUsed to accept text input from the user. SyntaxNotesUsing the Scanner class, the program can accept input from the user. The scanner class needs to be imported to the Java program. Scanner is the class name, userInput is the instance of the Scanner class. An instance of the scanner class is created, and from the object, a method can be called to take and parse the input. Once the scanner object is finished accepting input, it is closed to prevent a memory leak. Next() takes in the user's input, and breaks it up using a delimiter (usually a space). There several different Next methods that can be used. Most are used to restrict the type of data the user can input (for example, nextInt() ensures the user's input is an integer). When finished, the Scanner object needs to be closed using the close() method. Example
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |