質問編集履歴

1

誤字

2020/06/19 14:02

投稿

kamag
kamag

スコア0

test CHANGED
@@ -1 +1 @@
1
- txtファイルから読み取ったデータを計算する
1
+ txtファイルからデータ
test CHANGED
@@ -1,8 +1,6 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
3
 
4
-
5
- 「○日,商品名:金額」の形のデータがいくつか入ったtxtファイルを読み取り、1日目、2日目、3日目それぞれの出金の合計を求めたいです。(日付は1~3日のみで良いです。)周りくどい方法をとっているかもしれませんが、できるだけ修正少なくこの方向性のまま完成させたいです。勉強し始めて1ヶ月ほどなので、あまり難しいことはできません。よろしくお願いします。
6
4
 
7
5
 
8
6
 
@@ -30,75 +28,7 @@
30
28
 
31
29
 
32
30
 
33
- public class Shopping{
34
31
 
35
- public static void main(String[] args){
36
-
37
- try{
38
-
39
- FileReader fr = new FileReader("Shopping.txt");
40
-
41
- BufferedReader br = new BufferedReader(fr);
42
-
43
- while(br.ready()){
44
-
45
- String str = br.readLine();
46
-
47
-
48
-
49
- String str2,str3;
50
-
51
- int day,pay;/*dayは日付、payは金額を入れる変数*/
52
-
53
- int index1,index2;
54
-
55
- index1 = str.indexOf("日");
56
-
57
- str2 = str.substring(0,index1);
58
-
59
- day = Integer.parseInt(str2);
60
-
61
-
62
-
63
- index2 = str.indexOf(":");
64
-
65
- str3 = str.substring(index2 + 1);
66
-
67
- pay = Integer.parseInt(str3);
68
-
69
-
70
-
71
- int count1=0,count2=0,count3=0;
72
-
73
- while(day == 1){
74
-
75
- count1 = count1 + pay;
76
-
77
- }
78
-
79
- while(day == 2){
80
-
81
- count2 = count2 + pay;
82
-
83
- }
84
-
85
- while(day == 3){
86
-
87
- count3 = count3 + pay;
88
-
89
- }
90
-
91
- }
92
-
93
- br.close();
94
-
95
- fr.close();
96
-
97
- }
98
-
99
- catch (IOException e) {
100
-
101
- }
102
32
 
103
33
  }
104
34