星期四, 六月 29, 2006
Java 把数字从低向高排序
import java.io.*;
public class Order
{
public static void main(String[] args) throws Exception
{
if(args.length<1) dataf=" new" style="font-weight: bold; color: rgb(255, 0, 0);">BufferedReader d = new BufferedReader(new InputStreamReader(new FileInputStream(dataf)));
String line="";
StringBuffer out =new StringBuffer();
while( (line=d.readLine())!=null)
{
String[] all=line.split("[\t,]");
int[] number = Str2Int(all);
java.util.Arrays.sort(number);
out.append(int2Str(number)).append("\n");
}
System.out.println(out);
}
/*
*把int数组转换为字符串数组
*/
static String int2Str(int[] ori)
{
StringBuffer result = new StringBuffer();
for(int i=0;i<ori.length;i++)
result.append(ori[i]).append("\t");
return result.toString();
}
/*
*把数组转换为字符int串数组
*/
static int[] Str2Int(String[] ori)
{
int[] result= new int[ori.length];
for(int i=0;i<result.length;i++)result[i]=Integer.parseInt(ori[i]);
return result;
}
}
订阅:
博文 (Atom)