Scanner class (read the command line input number)

Source: Internet
Author: User

1 //Fig. 2.7:addition2.java, command line Add "Java University Basic Tutorial _ Sixth Edition 43rd page"2 3  PackageFirst ;4 5 ImportJava.util.Scanner;//Program uses class Scanner6 7  Public classAddition2 {8      Public Static voidMain (String args[]) {9Scanner input =NewScanner (system.in);Ten          One         intNumber1; A         intnumber2; -         intsum; -          theSystem.out.print ("Enter First integer:"); -Number1 =input.nextint (); -          -System.out.print ("Enter Second integer:"); +Number2 =input.nextint (); -          +sum = Number1 +number2; A          atSystem.out.printf ("Sum is%d\n", sum); -          - Input.close (); The original book does not have this line, scanner class objects to close after use -     } -  -}

Eclipse is smart, when there is no 25th line of code, line 9th will prompt: Scanner object needs to be closed, and can bring up the introduction about the Close method

Scanner class (read the command line input number)

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.