當前位置:編程學習大全網 - 編程軟體 - 編程:利用隨機數產生10000個0~100之間的考試分數,將其存入壹個文本文件中,然後程序從這個文件中讀取這

編程:利用隨機數產生10000個0~100之間的考試分數,將其存入壹個文本文件中,然後程序從這個文件中讀取這

import java.io.*;

//我寫的。。。希望對妳有用。。。

public class H1 {

public static void main(String args[]) throws IOException {

int read;

String outfilename = "c:\\1.txt";

File fout = new File(outfilename);

PrintWriter out = new PrintWriter(new FileWriter(fout));

for (int i = 0; i <= 10000; i++) {

read = (int) (Math.random() * (100 - 0 + 1) + 0);// 這是取範圍隨機數的模型。。。

out.print(read + "\n");

}

out.close();

try {

FileInputStream fis = new FileInputStream("c:\\1.txt");

InputStreamReader isr = new InputStreamReader(fis);

LineNumberReader lnr = new LineNumberReader(isr);

String s = null;

int i;

while ((s = lnr.readLine()) != null) {

i = Integer.parseInt(s);

System.out.println("The decimal read: " + i);

}

}

catch (Exception e) {

e.printStackTrace();

}

}

}

  • 上一篇:任縣大風車幼兒園怎麽樣
  • 下一篇:三菱加工中心if診斷使用方法
  • copyright 2024編程學習大全網