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.