到底是那里有问题啊!!!(知道的看一下,不耽误多少功夫)

来源:百度知道 编辑:UC知道 时间:2024/05/25 00:17:21
import java.io.*;
public class XuanZhe {
public static void fac(int a[]){
int i=0;
int min;
int temp=i;
for(i=0;i<a.length;i++){
for(int j=a.length-1;j>i;j--){
if(a[temp]>a[j])
temp=j;
}
min=a[i];
a[i]=a[temp];
a[temp]=min;
System.out.println(a[i]);
}
}
public static void main(String args[]){
int z[]=new int[5];
try{
System.out.println("请输入数字:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<z.length;i++){
z[i]=Integer.parseInt(br.readLine());
}
XuanZhe.fac(z);
}catch(IOException e){}

}

}
输入8 6 4 9 7 输出4 7 6 8 9

一楼用的是冒泡排序吧!我想用选择排序做。
二楼说的是错的!!!

import java.io.*;

public class XuanZhe {
public static void fac(int a[]) {
int i = 0;
int min;
// int temp = i;
for (i = 0; i < a.length; i++) {
for (int j = a.length - 1; j > i; j--) {
if (a[i] > a[j]) {
min = a[j];
a[j] = a[i];
a[i] = min;
// temp = i;
}
}

System.out.println(a[i]);
}
}

public static void main(String args[]) {
int z[] = new int[5];
try {
System.out.println("请输入数字:");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
for (int i = 0; i < z.length; i++) {
z[i] = Integer.parseInt(br.readLine());