求一个Java程序,要求输入几个数,然后按照由小到大的顺序排列!

来源:百度知道 编辑:UC知道 时间:2024/09/21 03:26:25
谢谢

//我帮你做作
import java.io.*;
class Test{
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;
}
}

PoPo popo = new PoPo(num, i);
popo.sort();
}
}

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 void sort()
{
int i = 0;
int j = 0;
int temp = 0;
for(i = 0; i < length; i++)