forked from 21311219kn/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.java
More file actions
35 lines (32 loc) · 989 Bytes
/
Copy pathsum.java
File metadata and controls
35 lines (32 loc) · 989 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
import java.util.Random;
import java.io.*;
class sum {
public static void main(String args[])
{
// 変数aをtensu.txtにファイル出力する
try{
// tensu.txtに書き込む準備
File file = new File("tensu.csv");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
// 読み込んだデータをコンマで分割する
String datas = br.readLine();
String[] str1Ary = datas.split(",");
int [] idatas=new int[str1Ary.length];
int sum=0;
// 分割された文字列の表示
for (int i=0; i<str1Ary.length; i++) {
// idatas[i]に、str1Ary[i]をint型にキャストして代入
idatas[i]=Integer.valueOf(str1Ary[i]).intValue();
sum=sum+idatas[i];
System.out.println(str1Ary[i]);
}
System.out.println("合計="+sum);
// ファイルを閉じる
br.close();
} catch(Exception e)
{
System.out.println(e.toString());
}
}
}