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.