/**
* 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