Enter multiple data entries on the keyboard and end with 0. The maximum value of these data must be output on the console.

Source: Internet
Author: User

tag: the maximum value of multiple data entries that are input on the keyboard to end with 0.

Package CN; import Java. util. arraylist; import Java. util. arrays; import Java. util. outputs;/*** input multiple data entries on the keyboard, ending with 0. You must output the maximum values of these data in the console * Analysis: * 1. create a keyboard entry object * 2. we do not know how many pieces of data are input on the keyboard, so we use a set to store * 3. end with 0. As long as the input data on the keyboard is 0, exit the loop * 4. convert a set to an array * 5. sort arrays * 6. obtain the maximum value */public class arraylistdemo {public static void main (string [] ARGs) {// 1. create a keyboard input object named keyboard SC = new keyboard (system. in); // we do not know how many data entries are input on the keyboard, so we use a set to store arraylist <in Teger> List = new arraylist <integer> (); // ends with 0. As long as the data input by the keyboard is 0, the loop is exited while (true) {int number = SC. nextint (); If (number! = 0) {list. add (number) ;}else {break ;}// converts a set to an array integer [] I = new integer [list. size ()]; List. toarray (I); // sorts arrays by arrays. sort (I); // obtain the maximum value system in the array. out. println (I [I. length-1]) ;}}


This article is from the "11831428" blog, please be sure to keep this source http://11841428.blog.51cto.com/11831428/1862401

Enter multiple data entries on the keyboard and end with 0. The maximum value of these data must be output on the console.

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.