Java startup -- output descending order

Source: Internet
Author: User
Tags array sort

/*
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All Rights Reserved.
* File Name:
* Author: Zhang chuanxin
* Completion date: January 1, September 22, 2012
* Version No.: j.1.05

* Description of tasks and Solutions
* Input description:
* Problem description: For an integer greater than three digits, output the descending order number. For example, if the integer is 82319, the descending order is 98321.

* Algorithm tip: extract the numbers of Integers to one-dimensional array a, sort the elements in array a in descending order, and finally output the element values in array.

* Program output: output the descending order of a number.

* Problem Analysis: Sort each bit of a number in descending order
* Algorithm Design: extract each bit of the current number and place it in the reward array. Sort the elements in the array by Bubble sorting method in the throat, and finally output the array elements.
*/

Public class testsort {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubsort (82319 );} // calculate the descending order of the given number static void sort (int n) {int sort []; // create an array sort = new int [5]; // open a new space for the array int M = N; For (INT I = 0; m> 0; I ++) {// separate each digit into int s; S = m % 10; M = m/10; sort [I] = s ;} for (INT I = 1; I <sort. length; I ++) {// For (Int J = 0; j <I; j ++) {If (sort [I]> sort [J]) {int t; t = sort [I]; sort [I] = sort [J]; sort [J] = T ;}} system. out. the descending order of println (n + "is:"); For (INT I = 0; I <sort. length; I ++) {system. out. print (sort [I]) ;}}

Running result:

The descending order of 82319 is:
98321

Experience Accumulation: the establishment of arrays in Java is different from that in C ++.

First, declare the array, which only gives the array name and the Data Type of the array, int sort []; second, allocate memory space for the array, sort = new int [5].

/*
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All Rights Reserved.
* File Name:
* Author: Zhang chuanxin
* Completion date: January 1, September 22, 2012
* Version No.: j.1.05

* Description of tasks and Solutions
* Input description:
* Problem description: For an integer greater than three digits, output the descending order number. For example, if the integer is 82319, the descending order is 98321.

* Algorithm tip: extract the numbers of Integers to one-dimensional array a, sort the elements in array a in descending order, and finally output the element values in array.

* Program output: output the descending order of a number.

* Problem Analysis: Sort each bit of a number in descending order
* Algorithm Design: extract each bit of the current number and place it in the reward array. Sort the elements in the array by Bubble sorting method in the throat, and finally output the array elements.
*/

Public class testsort {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubsort (82319 );} // calculate the descending order of the given number static void sort (int n) {int sort []; // create an array sort = new int [5]; // open a new space for the array int M = N; For (INT I = 0; m> 0; I ++) {// separate each digit into int s; S = m % 10; M = m/10; sort [I] = s ;} for (INT I = 1; I <sort. length; I ++) {// For (Int J = 0; j <I; j ++) {If (sort [I]> sort [J]) {int t; t = sort [I]; sort [I] = sort [J]; sort [J] = T ;}} system. out. the descending order of println (n + "is:"); For (INT I = 0; I <sort. length; I ++) {system. out. print (sort [I]) ;}}

Running result:

The descending order of 82319 is:
98321

Experience Accumulation: the establishment of arrays in Java is different from that in C ++.

First, declare the array, which only gives the array name and the Data Type of the array, int sort []; second, allocate memory space for the array, sort = new int [5].

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.