質問編集履歴
3
文章変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
多次元配列の1行ごとの合計の出し方・成績表を作りたい
|
1
|
+
f多次元配列の1行ごとの合計の出し方・成績表を作りたい
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
### 該当のソースコード
|
18
18
|
|
19
|
-
```
|
19
|
+
```java
|
20
20
|
|
21
21
|
package jp.learningdesign.javastudy;
|
22
22
|
|
@@ -150,7 +150,7 @@
|
|
150
150
|
|
151
151
|
printNames() ;
|
152
152
|
|
153
|
-
をメインに
|
153
|
+
をメインにおきましたがエラーが出ます。
|
154
154
|
|
155
155
|
```
|
156
156
|
|
@@ -159,11 +159,3 @@
|
|
159
159
|
[])
|
160
160
|
|
161
161
|
```
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
### 補足情報(FW/ツールのバージョンなど)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
ここにより詳細な情報を記載してください。
|
2
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
### 発生している問題・エラーメッセージ
|
12
12
|
|
13
|
-
|
13
|
+
エラーコードは出ていないのですが、何も表示さないです。
|
14
14
|
|
15
15
|
|
16
16
|
|
@@ -18,85 +18,121 @@
|
|
18
18
|
|
19
19
|
```
|
20
20
|
|
21
|
-
p
|
21
|
+
package jp.learningdesign.javastudy;
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
|
25
|
+
class Task2_Lab5 {
|
26
26
|
|
27
|
-
|
27
|
+
|
28
28
|
|
29
|
-
|
29
|
+
public static void main(String[] args) {
|
30
30
|
|
31
|
-
|
31
|
+
//1. input
|
32
32
|
|
33
|
-
|
33
|
+
String[][] names = {
|
34
34
|
|
35
|
-
|
35
|
+
{"Ewell ", "Nate"},
|
36
36
|
|
37
|
-
|
37
|
+
{"Smurthwaite ", "Adelina"},
|
38
38
|
|
39
|
+
{"Bernollet ", "Maryjane"},
|
40
|
+
|
41
|
+
{"Chalfain ", "Karlis"},
|
42
|
+
|
39
|
-
|
43
|
+
{"Huckabe ", "Almire"}
|
44
|
+
|
45
|
+
};
|
46
|
+
|
47
|
+
double[][] grades = {
|
48
|
+
|
49
|
+
{3.83, 9.21, 9.25, 0.84, 1.40, 7.90, 1.41, 5.15},
|
50
|
+
|
51
|
+
{5.09, 3.66, 3.04, 3.02, 8.59, 2.34, 8.86, 7.40},
|
52
|
+
|
53
|
+
{5.35, 0.85, 8.56, 7.37, 2.78, 3.19, 2.04, 5.70},
|
54
|
+
|
55
|
+
{9.25, 9.62, 7.08, 7.27, 9.86, 5.88, 9.86, 9.70},
|
56
|
+
|
57
|
+
{3.39, 2.75, 1.23, 1.04, 3.87, 8.72, 4.60, 6.21}
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
public double classAverage(double[][] grades, double classAverage) {
|
40
66
|
|
41
67
|
|
42
68
|
|
69
|
+
// avg of per line
|
70
|
+
|
71
|
+
double[] personAvg = new double[grades.length];
|
72
|
+
|
73
|
+
for (int i = 0; i < grades.length; i++) {
|
74
|
+
|
43
|
-
|
75
|
+
double Sum = 0;
|
76
|
+
|
77
|
+
for (int j = 0; j < grades[i].length; j++) {
|
44
78
|
|
45
79
|
|
46
80
|
|
47
|
-
double
|
81
|
+
double classSum = 0;
|
48
82
|
|
49
|
-
|
83
|
+
double classAvg = 0;
|
50
84
|
|
51
|
-
|
85
|
+
}
|
52
86
|
|
53
|
-
|
87
|
+
|
54
88
|
|
55
|
-
|
89
|
+
double classAvg = ((Sum / grades.length) / grades[0].length);
|
56
|
-
|
57
|
-
{3.39, 2.75, 1.23, 1.04, 3.87, 8.72, 4.60, 6.21}
|
58
|
-
|
59
|
-
};
|
60
90
|
|
61
91
|
|
62
92
|
|
63
|
-
|
93
|
+
personAvg[i] = Sum / grades[i].length;// 1行の平均
|
64
94
|
|
65
|
-
|
95
|
+
System.out.println("each students average " + personAvg[i]);
|
66
96
|
|
67
|
-
|
97
|
+
System.out.println("class average " + classAvg);
|
68
98
|
|
69
99
|
|
70
100
|
|
71
|
-
|
101
|
+
}
|
72
102
|
|
73
|
-
|
103
|
+
return classAverage;
|
74
104
|
|
75
|
-
|
105
|
+
}
|
76
106
|
|
107
|
+
|
77
108
|
|
109
|
+
public void printNames(String[][] names, double[] personAvg) {
|
78
110
|
|
79
|
-
|
111
|
+
String students = " ";
|
80
112
|
|
113
|
+
for (int i = 0; i < names.length; i++) {
|
81
114
|
|
115
|
+
for (int j = names[i].length - 1; j >= 0; j--) {
|
82
116
|
|
83
|
-
|
117
|
+
students += " " + names[i][j];
|
84
118
|
|
119
|
+
}
|
85
120
|
|
121
|
+
students += "\t" + personAvg[i];
|
86
122
|
|
87
|
-
|
123
|
+
}
|
88
124
|
|
89
|
-
System.out.print(
|
125
|
+
System.out.print(students + "\t\n");
|
90
126
|
|
91
|
-
|
127
|
+
students = "";
|
92
128
|
|
93
|
-
|
129
|
+
|
94
130
|
|
131
|
+
|
95
132
|
|
133
|
+
}
|
96
134
|
|
97
|
-
|
135
|
+
}
|
98
|
-
|
99
|
-
}
|
100
136
|
|
101
137
|
```
|
102
138
|
|
@@ -104,7 +140,25 @@
|
|
104
140
|
|
105
141
|
### 試したこと
|
106
142
|
|
143
|
+
classAverage(grades);
|
144
|
+
|
145
|
+
printNames(names) ;
|
146
|
+
|
147
|
+
や
|
148
|
+
|
149
|
+
classAverage();
|
150
|
+
|
151
|
+
printNames() ;
|
152
|
+
|
153
|
+
をメインに置く。
|
154
|
+
|
155
|
+
```
|
156
|
+
|
107
|
-
|
157
|
+
The method classAverage(double[][], double) in the type Task2_Lab5 is not applicable for the arguments (double[]
|
158
|
+
|
159
|
+
[])
|
160
|
+
|
161
|
+
```
|
108
162
|
|
109
163
|
|
110
164
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
2次元配列を使った成績表を作っています。
|
4
|
+
|
5
|
+
完成イメージはこのように名前と平均成績の表を出したいです。
|
4
6
|
|
5
7
|
![完成イメージ](74949cbcbbb1b23d90e19e69f19d19e1.png)
|
6
8
|
|