<span>int</span> [] array1 = {1,3,5,7,9,10,2,15,154,10,2,188,200};<span>//</span><span>定义一个数组,内容为混乱大小</span> <span>int</span> index = 0;<span>//</span><span>定义一个最大值或最小值的位置</span> <span>int</span> keyValue = 0;<span>//</span><span>定义最大值或最小值</span> <span>int</span> temp = 0;<span>//</span><span>定义一个临时存储变量</span> <span>for</span>(<span>int</span> i=0;i<array1.length;i++){<span>//</span><span>依次循环所有数据</span> index = i;<span>//</span><span>将i位置赋值给index</span> keyValue = array1[index];<span>//</span><span>将i位置的值赋值给keyValue</span> <span>for</span>(<span>int</span> y=i;y<array1.length;y++){<span>//</span><span>再次循环所有变量,不过这次是长度起始长度为i,最大长度不变</span> <span>if</span>(array1[y] < keyValue){<span>//</span><span>如果循环到的值小于i位置的值</span> index = y;<span>//</span><span>位置重新定义为当前位置</span> keyValue = array1[y];<span>//</span><span>最小值为当前位置</span> <span> } } temp </span>= array1[i];<span>//</span><span>将i位置的值赋值给临时变量(最大值)</span> array1[i] = array1[index];<span>//</span><span>将i位置重新定义为index(最小)位置的</span> array1[index] = temp;<span>//</span><span>将最大值重新定义给index位置,实现交换过程</span> <span> } </span><span>for</span>(<span>int</span> p=0;p<array1.length;p++<span>){ System.out.print(array1[p]</span>+" "<span>); }</span>