Those years, learn together Java 7-3

Source: Internet
Author: User

/**

* 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

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.