import java.io.*;
public class Text13_9_1 {
public static void main(String[] args) throws IOException
{
FileWriter fw=new FileWriter("C:\\Documents and Settings\\user\\桌面\\rand.txt");
BufferedWriter bfw=new BufferedWriter(fw);
for(int i=1;i<=50;i++)
{
for(int j=1;j<=20;j++ )
{
bfw.write(Integer.toString((int)(100000*(Math.random())))+" ");
}
bfw.newLine();
}
bfw.flush();
fw.close();
int data[]=new int[1000];
double total=0.0;
DataInputStream in=new DataInputStream(new FileInputStream("C:\\Documents and Settings\\user\\桌面\\rand.txt"));
for(int i=0;i<data.length;i++)
{
data[i]=in.readInt();
in.skip(1);
if((i+1)%20==0)
{
in.readLine();
}
total+=data[i]/1000.0;
}
for(int i=0;i<data.length-1;i++)
for(int j=i+1,t;j<data.length;j++)
if(data[i]>data[j])
{
t=data[i];data[i]=data[j];data[j]=t;
}
System.out.println("这1000个数中最大的整数是:"+data[data.length-1]+",最小的整数是:"+data[0]+",平均数是:"+total);
System.out.println("从小到大排列顺序是:");
for(int i=0;i<data.length;i++)
{
System.out.print(data[i]+" ");
if((i+1)%20==0)System.out.println();
}
}
}
文件的读写