/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package array; import java.util.Arrays; /** * * @author Administrator */ public class Demo4 { public static void main(String[] args){ int[] a = {5,7,6,1,8,3}; int[] temp = stroe(a); System.out.println(Arrays.toString(temp)); } public static int[] stroe(int[] arrays){ //创建一个空值用于交换 int temp = 0; //判断需要循环多少次 for(int i=0;i<arrays.length-1;i++){ //判断两个数谁大,大的话交换位置 for(int j=0;j<arrays.length-1-i;j++){//减i是为了减少无用的循环次数 if(arrays[j]<arrays[j+1]){ temp = arrays[j]; arrays[j] = arrays[j+1]; arrays[j+1] = temp; } } } return arrays; } }