質問編集履歴
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,157 +25,3 @@
|
|
25
25
|
return: int num;に対して このメソッドは型 int の結果を戻す必要があります
|
26
26
|
|
27
27
|
重複ローカル変数 numと出ます
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
### 該当のソースコード
|
32
|
-
|
33
|
-
```html
|
34
|
-
|
35
|
-
package org.mypackage.sample;
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
import java.io.IOException;
|
40
|
-
|
41
|
-
import java.io.PrintWriter;
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
import javax.servlet.ServletException;
|
46
|
-
|
47
|
-
import javax.servlet.annotation.WebServlet;
|
48
|
-
|
49
|
-
import javax.servlet.http.HttpServlet;
|
50
|
-
|
51
|
-
import javax.servlet.http.HttpServletRequest;
|
52
|
-
|
53
|
-
import javax.servlet.http.HttpServletResponse;
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
/**
|
58
|
-
|
59
|
-
* Servlet implementation class Method4
|
60
|
-
|
61
|
-
*/
|
62
|
-
|
63
|
-
@WebServlet("/Method4")
|
64
|
-
|
65
|
-
public class Method4 extends HttpServlet {
|
66
|
-
|
67
|
-
private static final long serialVersionUID = 1L;
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
/**
|
72
|
-
|
73
|
-
* @see HttpServlet#HttpServlet()
|
74
|
-
|
75
|
-
*/
|
76
|
-
|
77
|
-
public Method4() {
|
78
|
-
|
79
|
-
super();
|
80
|
-
|
81
|
-
// TODO Auto-generated constructor stub
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
/**
|
88
|
-
|
89
|
-
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
90
|
-
|
91
|
-
*/
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
/*メソッド*/
|
96
|
-
|
97
|
-
int calculation(){
|
98
|
-
|
99
|
-
/*四則演算*/
|
100
|
-
|
101
|
-
int num=100+200;
|
102
|
-
|
103
|
-
/*戻り値*/
|
104
|
-
|
105
|
-
return: int num;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
114
|
-
|
115
|
-
// TODO Auto-generated method stub
|
116
|
-
|
117
|
-
response.setContentType("text/html;charset=UTF-8");
|
118
|
-
|
119
|
-
try (PrintWriter out = response.getWriter()) {
|
120
|
-
|
121
|
-
/*戻り値を呼び出す?*/
|
122
|
-
|
123
|
-
int num =calculation ();
|
124
|
-
|
125
|
-
/*条件分岐*/
|
126
|
-
|
127
|
-
if(num>=200) {
|
128
|
-
|
129
|
-
out.print("200以上です。");
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
else if(num>=100) {
|
134
|
-
|
135
|
-
out.print("100以上です。");
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
else {
|
140
|
-
|
141
|
-
out.print("100未満です。");
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
/**
|
154
|
-
|
155
|
-
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
156
|
-
|
157
|
-
*/
|
158
|
-
|
159
|
-
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
160
|
-
|
161
|
-
// TODO Auto-generated method stub
|
162
|
-
|
163
|
-
doGet(request, response);
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
```
|
172
|
-
|
173
|
-
```ここに言語名を入力
|
174
|
-
|
175
|
-
java
|
176
|
-
|
177
|
-
```
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
指摘宜しくお願いします
|
2
文書の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
ユーザー定義メソッドcalculation内で行った四則演算の結果を戻り値として呼び出し元へ返し、
|
7
|
+
ユーザー定義メソッドint 型で作った calculation内で行った四則演算 int num=100+200; の結果を戻り値 として呼び出し元へ返し、
|
8
8
|
|
9
|
-
その後条件分岐、200以上 ... 「200以上です。」と表示
|
9
|
+
その後条件分岐にて、200以上 ... 「200以上です。」と表示
|
10
10
|
|
11
11
|
100以上200未満 ... 「100以上200未満です。」と表示
|
12
12
|
|
@@ -96,9 +96,11 @@
|
|
96
96
|
|
97
97
|
int calculation(){
|
98
98
|
|
99
|
-
|
99
|
+
/*四則演算*/
|
100
100
|
|
101
101
|
int num=100+200;
|
102
|
+
|
103
|
+
/*戻り値*/
|
102
104
|
|
103
105
|
return: int num;
|
104
106
|
|
@@ -116,7 +118,11 @@
|
|
116
118
|
|
117
119
|
try (PrintWriter out = response.getWriter()) {
|
118
120
|
|
121
|
+
/*戻り値を呼び出す?*/
|
122
|
+
|
119
|
-
|
123
|
+
int num =calculation ();
|
124
|
+
|
125
|
+
/*条件分岐*/
|
120
126
|
|
121
127
|
if(num>=200) {
|
122
128
|
|
1
簡潔化
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
java
|
1
|
+
javaの戻り値の使い方がいまいち分かりません指摘お願いします。
|
test
CHANGED
@@ -4,13 +4,15 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
ユーザー定義メソッドcalculation内で行った四則演算の結果を戻り値として呼び出し元へ返し、
|
7
|
+
ユーザー定義メソッドcalculation内で行った四則演算の結果を戻り値として呼び出し元へ返し、
|
8
8
|
|
9
9
|
その後条件分岐、200以上 ... 「200以上です。」と表示
|
10
10
|
|
11
11
|
100以上200未満 ... 「100以上200未満です。」と表示
|
12
12
|
|
13
13
|
100未満 ... 「100未満です。」と表示させたいのですが
|
14
|
+
|
15
|
+
戻り値がどこに返せばいいのかいまいち理解できていませんご指摘宜しくお願いします。
|
14
16
|
|
15
17
|
|
16
18
|
|
@@ -27,6 +29,8 @@
|
|
27
29
|
|
28
30
|
|
29
31
|
### 該当のソースコード
|
32
|
+
|
33
|
+
```html
|
30
34
|
|
31
35
|
package org.mypackage.sample;
|
32
36
|
|
@@ -158,7 +162,7 @@
|
|
158
162
|
|
159
163
|
}
|
160
164
|
|
161
|
-
|
165
|
+
```
|
162
166
|
|
163
167
|
```ここに言語名を入力
|
164
168
|
|