Java's Scanner class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.