package com.who;public class SelectSort { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // 創建一個數組,這個數組的元素是亂序的 int[] array = { 63, 4, 24, 1, 3, 15 }; // 創建類對象 SelectSort sorter = new SelectSort(); // 調用對象的排序方法 sorter.sort(array); } public void sort(int[] array) { for (int i = 1; i < array.length; i++) { int index = 0; for (int j = 1; j <= array.length - i; j++) { if (array[index] < array[j]) { index = j; } } int temp = array[array.length - i]; array[array.length - i] = array[index]; array[index] = temp; } ShowArray(array); } public void ShowArray(int[] array) { for (int i = 1; i <= array.length; i++) { System.out.print(array[i] + " "); } System.out.println(); }}
一直報錯 不太懂
寶慕林9454223
2017-02-03 10:13:39