For more information about how to sort arrays, see Java.

Source: Internet
Author: User

For more information about how to sort arrays, see Java.

package com.swift;public class Xuanze {    public static void main(String[] args) {        int[] arr= {28,2,38,1,390,17,10,9,323};        for(int i=0;i<arr.length;i++) {            for(int j=i+1;j<arr.length;j++) {                if(arr[i]>arr[j]) {                    int temp;                    temp=arr[i];                    arr[i]=arr[j];                    arr[j]=temp;                }            }        }        for(int i=0;i<arr.length;i++) {            System.out.println(arr[i]);        }    }}

C ++ code:

# Include <iostream> using namespace std; int main () {// declare a one-dimensional array? An integer one-dimensional array, that is, all elements in the array are int arr [10] = {23,234,}; for (int I = 0; I <10; I ++) {cout <"the number of the one-dimensional array" <I <"the value is" <arr [I] <endl ;} // sort the array, which must be output from small to large (select) // for (int I = 0; I <10-1; I ++) {// for (int j = I + 1; I <10; j ++) {// if (array [I]> array [j]) {// int temp; // temp = array [I]; // array [I] = array [j]; // array [j] = temp; ///} //} for (int I = 0; I <10-1; I ++) {for (int j = I + 1; j <10; j ++) {if (arr [I]> arr [j]) {int temp; temp = arr [I]; arr [I] = arr [j]; arr [j] = temp ;}}// sort and traverse the character array for (int I = 0; I <10; I ++) {cout <"Number of the Second-dimensional array after traversing" <I <"value is" <arr [I] <endl ;}return 0 ;}

The second for starts to be written as I <10, and the memory cannot be read error occurs. j is infinitely larger, and the dev compiler does not have a valid prompt, which is not good.

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.