java冒泡排序,紧急啊

来源:百度知道 编辑:UC知道 时间:2024/05/22 03:49:42
排序,在命令行接受用户输入的N个数字,以-1作为结束标志,并且-1不计算在内,对这些输入的数字进行排序输出,并计算平均数.要求自己写排序算法,不用汉字,拼音做类名,注释等等.

我帮你做作 阿
import java.io.*;
public class main{
public static void main(String args[]) throws IOException
{
int num[] = new int[20];
int i = 0;
int temp = 0;
int sum = 0;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
while(true)
{
temp = Integer.parseInt(buf.readLine());
if(temp != -1)
{
num[i] = temp;
i++;
sum += temp;
}
else
{
break;
}
}
System.out.println("平均数:" + (sum / (i - 1)));
PoPo popo = new PoPo(num, i);
popo.sort();
}
}

public class PoPo{
int num[] = new int[20];
int flag = 0;
int length = 0;
public PoPo()
{
}
public PoPo(int[] Num, int i)
{
for(int j = 0; j < i; j++)
{
this.num[j] = Num[j];
}
length = i;

}

public vo