Those years, the Java 7-1_1 that we learned together

Source: Internet
Author: User

/**

* 7-1

* The program that writes the character interface, accepts a number of positive integers entered by the user,

*-1 indicates the end of the input.

* Sort the input data in descending order using the sort algorithm

* and print the results after each scan

* The runtime uses the following different data series to observe its execution results

* 1. There is only one data in the sequence

* 2. Duplicate data in a sequence

* 3. The data entered in the sequence is sorted in ascending order

* 4. The data entered in the sequence is sorted in descending order

**/

Import java.util.*;p ublic class test{public static void Main (string[] args) {System.out.println ("enter several integers to end with-1"); Scanner read = new Scanner (system.in); int s = 0; arraylist<integer> array = new arraylist<integer> (), while ((s = read.nextint ())! =-1) array.add (s);/* Descending sort ( Use the bubble sorting algorithm) and output the result after each scan */for (int i = 0; i < array.size (); i++) {for (int j = 0; J < array.size ()-i-1;j++) if (Array.get (j ) <array.get (j+1)) {int temp1 = Array.get (j); int temp2 = Array.get (j+1); Array.add (J, Temp2); Array.add (j+1, TEMP1);} for (int k = 0; k < array.size (); k++) System.out.print (Array.get (k) + ""); System.out.println ();}}}


Those years, the Java 7-1_1 that we learned together

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.