forked from 21311219kn/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.java
More file actions
36 lines (33 loc) · 813 Bytes
/
Copy pathfile.java
File metadata and controls
36 lines (33 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Random;
import java.io.*;
class file {
public static void main(String args[])
{
// 0~100までの乱数を100個コンマ区切りで
// ファイル出力する
// 0~100までの乱数をint型の変数aに求めて
// 出力
Random b = new Random();
// 変数aをtensu.txtにファイル出力する
try{
// tensu.txtに書き込む準備
File file = new File("tensu.csv");
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
// 100個乱数をファイルに書き出す
for(int i=1; i<=100;i++)
{
// 乱数を生成
int a =b.nextInt(101);
// ファイルに値を書き込む
pw.print(a+",");
}
// ファイルを閉じる
pw.close();
} catch(Exception e)
{
System.out.println(e.toString());
}
}
}