用JAVA编写排序的源程序

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:58:16
我编写了一个,可怎么都不能运行出正确答案,但是便宜是没有错误的哈.请帮帮忙啊.
public class innum
{
static int a[]=new int[6],j,t,k;
public static void main(String args[])
{
byte b[]=new byte[20];
String str;
try
{
for(k=0;k<=5;k++)
{
System.in.read(b);
str=new String(b);
a[k]=Integer.parseInt(str.trim());
}
}
catch (Exception e){}
for(j=1;j<=5;j++)
{
for(k=0;k<=5-j;k++)
if(a[k]>a[k+1])
{t=a[k];a[k]=a[k+1];a[k+1]=t;}
}

for(k=0;k<=5;k++)
System.out.print(a[k]+",");
}
}

我运行怎么是对的?
输参数的时候搞错了吧。
5 回车
4 回车
7 回车
8 回车
2 回车
5 回车
看结果,别连按回车,也别输入非数字。

import java.util.*;
public class sort {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
int[] a= new int[10];
Scanner s=new Scanner(System.in);
for(int i=0;i<a.length;i++)
{
System.out.println("输入:");
a[i]=s.nextInt();
}
Arrays.sort(a);
System.out.println("最大值"+a[a.length-1]);
System.out.println("最小值"+a[0]);
//也可以循环把数组都输出

}

}

你的好像是输入数据排序吧,输入的全是纯数字没有出现错误啊