2016/06/02 Study Record

Source: Internet
Author: User

11 small examples of exception throws

1  PackageDemo;2 3 ImportJava.util.Scanner;4 5  Public classRedtwo {6 7      Public Static voidMain (string[] args) {8         //TODO auto-generated Method Stub9Scanner in =NewScanner (system.in);TenSystem.out.println ("Please enter an integer"); One         BooleanStop =true; A          Do { -             Try { -Integer C =in.nextint (); theSystem.out.println ("The integer is" +c); -Stop =false; -}Catch(RuntimeException ex) { -System.out.println ("The number you enter are not integer"); +                 //System.out.println (In.next ()); \ - in.nextline (); +             } A  at} while(stop); -  -     } -  -}

where input.nextline () is critical, if there is no line, the program goes into a dead loop, because after an exception is thrown, the input stream marker is also at the last entered position, and this line of code moves the input stream marker to the next input position.

2016/06/02 Study Record

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.