1.Scanner class overview
Scanner class overview: JDK5 later used to get the user's amount of keyboard input
Construction method: Public Scanner (InputStream source)
Member Methods for 2.Scanner classes
Basic format:
Hasnextxxx () to determine if there is a next entry, in fact, XXX can be int,double and so on. If you need to decide whether to include the next string, you can omit xxx.
Nextxxx () Gets the next entry. XXX has the same meaning as in the previous method.
By default, scanner uses spaces, carriage returns, and so on as separators
Common methods:
public int Nextint ()
public boolean hasnextint ()
package com;import java.util.scanner;/** * Basic Format * public boolean hasnextint () * public Int nextint () */public class ScannerDemo { @SuppressWarnings (" Resource ") public static void main (String[] args) { //Creating Objects Scanner Sc = new scanner (system.in); system.out.println ("Please enter integer data:"); / /Get Data if (Sc.hasnextint ()) { int x = sc.nextint (); &nBsp; system.out.println ("x=" +x); }else{           SYSTEM.OUT.PRINTLN ("You entered the wrong data"); } }}
This article is from the "11831428" blog, please be sure to keep this source http://11841428.blog.51cto.com/11831428/1859250
Java's Scanner class