class ? ?AraayTest2{ public ?static ? void ? main(String[] args) { int arr ={5,1,6,4,2,8,9}; //排序前; selectSort(arr); //排序后; printArray(arr); ? ? } ? ? ? ? ? public ?static ? void ?selectSort(int[] ?arr)? ? ? ? ? ?{?? for(int ?x=0;x<arr.length-1;x++)??{ for(int ?y=x+1;y<arr.length;y++) { if(arr[x]>arr[y]) { int ?temp=arr[x]; arr[y]=arr[x]; ?temp=arr[y]; } ? ? ?? ?? public ?static ?void ?printArray(int[] ?arr) {System.out.print("[");for(int ?x=0;x<arr.length;x++){if(x!=arr.length-1) ?? System.out.print(arr[x]+","); ? else ? System.out.print(arr[x]+"]");?} } }? }?} ? }
2 回答
已采納

Caballarii
TA貢獻(xiàn)1123條經(jīng)驗(yàn) 獲得超629個(gè)贊
粗略看了一下,你這調(diào)換變量寫的就是錯(cuò)的
應(yīng)該是這樣
int??temp=arr[x]; arr[x]=arr[y]; ?a[y]=temp;
其他沒看
添加回答
舉報(bào)
0/150
提交
取消