Scanner Scanner Tool class

Source: Internet
Author: User

It realizes the type judgment of scanner content, type coercion.

Content to scan: String,double,float,integer

1  Public classGetData {2     Private StaticScanner Scanner;3     Static {4Scanner =NewScanner (system.in);5     }6 7     PrivateGetData () {8     }9 Ten     /** One * Return String type A      *  -      * @return -      */ the      Public StaticString getString () { -         returnscanner.nextline (); -     } -  +     /** - * Return float type, possibly null +      *  A      * @return at      */ -      Public StaticFloat getfloat () { -  -String string =scanner.nextline (); - Float F; -         Try { inf =float.parsefloat (string); -             returnF; to}Catch(NumberFormatException e) { +             //TODO auto-generated Catch block -             //e.printstacktrace (); the             return NULL; *         } $     }Panax Notoginseng  -     /** the * Gets the integer type value.  +      *  A      * @return the      */ +      Public StaticInteger Getinteger () { -String string =scanner.nextline (); $ integer integer; $         Try { -Integer =integer.parseint (string); -             returninteger; the}Catch(NumberFormatException e) { -             //e.printstacktrace ();Wuyi             return NULL; the         } -  Wu     } -  About     /** $ * Gets the double type value.  -      *  -      * @return -      */ A      Public StaticDouble getdouble () { +String string =scanner.nextline (); the Double integer; -         Try { $Integer =double.parsedouble (string); the             returninteger; the}Catch(NumberFormatException e) { the             //e.printstacktrace (); the             return NULL; -         } in     } the  the     /** About * Close Scanner the      */ the      Public Static voidClosescanner () { the scanner.close (); +     } -}

Scanner Scanner Tool 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.