1.Scanner Overview:
JDK5 later used to get the user's keyboard input
2.Scanner Method of Construction:
Public Scanner (InputStream source)
3. Case:
1 Packagecn.itcast_01;2 3 /*4 * Scanner: Used to receive keyboard input data. 5 * 6 * In front of the time:7 * A: Guide Package8 * B: Create object9 * C: Call methodTen * One * There is a static field under the System class: A * public static final inputstream in; standard input stream, corresponding to keyboard input. - * - * InputStream is = system.in; the * - * Class Demo { - * public static final int x = ten; - * public static final Student s = new Student (); + * } - * int y = demo.x; + * Student s = demo.s; A * at * - * Construction Method: - * Scanner (inputstream source) - */ - ImportJava.util.Scanner; - in Public classScannerdemo { - Public Static voidMain (string[] args) { to //Creating Objects +Scanner sc =NewScanner (system.in); - the intx =sc.nextint (); * $System.out.println ("x:" +x);Panax Notoginseng } -}
Java Basic Knowledge Hardening 29:scanner Class Scanner overview