first, the most commonly used bubble sort (easy to remember) two-layer cycle is 0 to length-1, the second layer of multi-minus I more efficient, exchange for two adjacent
for (int i=0;i<score.length-1;i++) {
for (int j=0;j<score.length-1;j++) {
if (Score[j]>score[j+1]) {//change symbols in descending order
int T=SCORE[J];
SCORE[J]=SCORE[J+1];
score[j+1]=t;
}
}
}
Second, the most common sort of two (compare adjacent two)
for (int i=0;i<score.length-1;i++) {
for (int j=i+1;j<score.length;j++) {
if (Score[i]>score[j]) {//change symbols in descending order
int t=score[i];
SCORE[I]=SCORE[J];
score[j]=t;
}
}
}
Third, call the system method
int[] Arrray = new ARRAY[10];
Arrays.sort (array);//ascending order
There are also various data types in this method, from an index to the sort of an index
1.22 Java Basics Summary Most commonly used bubbling sort