/**
* 7-3
* Programmed to receive a number of data entered by the user, sorting them in descending order.
* Again accept a number entered by the user, using the method to find the data in the sequence,
* If present, outputs the number of the data in the sequence,
* If there is no output, the number is not in the sequence
**/
import java.util.*;p ublic class test{public static void main (String Args[]) {Scanner read = new scanner (system.in); System.out.println ("Please enter a number of integers to end with-1"); Arraylist<integer> array = new arraylist<integer> (); int i, j, s = 0;while ((S = read.nextint ()) != -1) Array.add (s);int[] arrays = new int[array.size ()];for ( i = 0; i < array.size (); i+ +) Arrays[i]=array.get (i);/* First Use the system functions in ascending order, and then change to descending order */arrays.sort (arrays); SYSTEM.OUT.PRINTLN ("After system sequencing");for (j = 0; j < arrays.length; j++) System.out.print (arrays[j]+ " "); System.out.println ();for (j = 0, i = arrays.length-1; j < i; j++, i--) {int temp = arrays[j];arrays[j] = arrays[i];arrays[i] = temp;} /* Output sorted array elements */system.out. println ("Self-sorting");for (int m = 0; m < arrays.length; m++) System.out.print (arrays[m]+ " "); System.out.println ();/* Use system functions to achieve binary search */int l = 0; System.out.print ("Enter the number to find:"); Int n = 0;n = read.nextint ();l = Arrays.binarysearch (arrays, n);//system.out.println ("Digital " + n + " " Subscript is ( Counting starting from 0): " + l";if (l >= 0) System.out.println ("Digital " + n + The subscript for is (counting from 0): + l); ElseSystem.out.println ("There is no in sequence" + n);}}
Those years, learn together Java 7-3