Those years, learn together Java 7-1

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) {Scanner input=new Scanner (system.in); int i = 0, S = 0;int array[] = new INT[100]; System.out.println ("Enter several positive integers, ending with 1");/* Enter several integers */while ((s = input.nextint ()) =-1) array[i++] = s;/* Sorts the input data using the Bubbling Sorting algorithm */for (int j = 0; J < i; J + +) {for (int k = 0; k < i-j-1; k++) {int temp = 0;IF (Array[k] < array [K+1]) {temp = array[k];array[k]=array[k+1];array[k+1]=temp;}} for (int l = 0; l < i; l++) System.out.print ("" + Array[l] + ""); System.out.println ();}}}


Those years, learn together Java 7-1

Related Article

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.