Third assignment: Learning from Scanner

Source: Internet
Author: User

ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {intNextValue; intSum=0; Scanner Kbinput=NewScanner (system.in); Kbinput.usedelimiter ("\\s");//Specify a space as a delimiter     while(Kbinput.hasnextint ()) {//Judging if there are no integers to readNextValue =Kbinput.nextint (); Sum+=NextValue; } System.out.println ("Sum:" +sum);
System.out.printf ("sum:%d", Sum); Kbinput.close (); //Close Stream Object}}

The results of the operation are as follows:

5 5 5 5
Sum:20
Sum:20

Enter any number, with a space to separate each number, press ENTER will automatically find the number of the and.

This assignment mainly studied the Usedelimiter in scanner. This function is used to set the delimiter, this time the job with a space as a delimiter ("\\s").

Also learned the Hasnextint in scanner, which is used to determine whether there is an integer readable.

The work in the teacher's classroom to explain the help, the use of new knowledge, the successful completion of this assignment!

==================================================================================

-----------------------------------------Split Line----------------------------------------

==================================================================================

After the discussion of our group Gao Yunpeng, Zheng, Zhang Cheng and Kezehui, our final works are ready to be made according to the three-person fighting landlord.

Interface preliminary plan.

Third assignment: Learning from Scanner

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.