質問編集履歴
8
変更しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -114,6 +114,8 @@
|
|
114
114
|
|
115
115
|
while (true) {
|
116
116
|
|
117
|
+
|
118
|
+
|
117
119
|
line = getInput();
|
118
120
|
|
119
121
|
if (line.equals("finish")) {
|
@@ -154,7 +156,13 @@
|
|
154
156
|
|
155
157
|
String[] abc = line.split(",");
|
156
158
|
|
159
|
+
if (line.equals("finish")) {
|
160
|
+
|
161
|
+
return "finish";
|
162
|
+
|
163
|
+
} else
|
164
|
+
|
157
|
-
a = Double.parseDouble(abc[0]);
|
165
|
+
a = Double.parseDouble(abc[0]);
|
158
166
|
|
159
167
|
b = Double.parseDouble(abc[1]);
|
160
168
|
|
@@ -162,11 +170,7 @@
|
|
162
170
|
|
163
171
|
System.out.println("line=" + a + ", " + b + ", " + c);
|
164
172
|
|
165
|
-
} catch (String q) {//ここで"finish"をキャッチしたいです。
|
166
|
-
|
167
|
-
System.out.printf("");
|
168
|
-
|
169
|
-
} catch (NumberFormatException | IOException e) {//
|
173
|
+
} catch (NumberFormatException | IOException e) {//
|
170
174
|
|
171
175
|
System.out.println("Could you enter the number?");
|
172
176
|
|
7
修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,117 +98,115 @@
|
|
98
98
|
|
99
99
|
import java.util.Scanner;
|
100
100
|
|
101
|
+
|
102
|
+
|
101
103
|
public class nijikannsuu {
|
102
104
|
|
103
105
|
|
104
106
|
|
105
107
|
public static void main(String[] args) {
|
106
108
|
|
107
|
-
String line="";
|
109
|
+
String line = "";
|
108
|
-
|
110
|
+
|
109
|
-
double a=0,b=0,c=0;
|
111
|
+
double a = 0, b = 0, c = 0;
|
110
112
|
|
111
113
|
boolean terminate = false;
|
112
114
|
|
113
|
-
while(true) {
|
115
|
+
while (true) {
|
114
|
-
|
116
|
+
|
115
|
-
line=getInput();
|
117
|
+
line = getInput();
|
116
|
-
|
118
|
+
|
117
|
-
if(line.equals("finish")) {
|
119
|
+
if (line.equals("finish")) {
|
118
120
|
|
119
121
|
System.out.println("Thanks you for using this system.");
|
120
122
|
|
121
123
|
return;
|
122
124
|
|
123
|
-
}else {
|
125
|
+
} else {
|
124
|
-
|
125
|
-
|
126
|
+
|
126
|
-
|
127
|
-
|
127
|
+
|
128
|
-
|
129
|
-
a=Double.parseDouble(abc[0]);
|
130
|
-
|
131
|
-
b=Double.parseDouble(abc[1]);
|
132
|
-
|
133
|
-
c=Double.parseDouble(abc[2]);
|
134
|
-
|
135
|
-
} catch(NumberFormatException e) {
|
136
|
-
|
137
|
-
System.out.println("Your Paramaters cannot understand.");
|
138
|
-
|
139
|
-
break;
|
140
128
|
|
141
129
|
}
|
142
130
|
|
143
131
|
}
|
144
132
|
|
145
|
-
}
|
146
|
-
|
147
133
|
}
|
148
134
|
|
149
135
|
|
150
136
|
|
151
137
|
public static String getInput() {
|
152
138
|
|
153
|
-
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
139
|
+
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
154
|
-
|
140
|
+
|
155
|
-
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
141
|
+
double a = 0, b = 0, c = 0, d = 0, x1 = 0, x2 = 0;
|
156
142
|
|
157
143
|
String line = null;
|
158
144
|
|
159
|
-
Scanner sc=new Scanner(System.in);
|
145
|
+
Scanner sc = new Scanner(System.in);
|
160
|
-
|
146
|
+
|
161
|
-
|
147
|
+
System.out.println("Please Input: a,b,c");
|
148
|
+
|
149
|
+
String q = "finish";
|
162
150
|
|
163
151
|
try {
|
164
152
|
|
165
|
-
for(int i=0; i<3; i++) {
|
166
|
-
|
167
|
-
|
153
|
+
line = reader.readLine();
|
154
|
+
|
168
|
-
|
155
|
+
String[] abc = line.split(",");
|
156
|
+
|
157
|
+
a = Double.parseDouble(abc[0]);
|
158
|
+
|
159
|
+
b = Double.parseDouble(abc[1]);
|
160
|
+
|
161
|
+
c = Double.parseDouble(abc[2]);
|
162
|
+
|
169
|
-
|
163
|
+
System.out.println("line=" + a + ", " + b + ", " + c);
|
164
|
+
|
170
|
-
|
165
|
+
} catch (String q) {//ここで"finish"をキャッチしたいです。
|
166
|
+
|
167
|
+
System.out.printf("");
|
168
|
+
|
171
|
-
|
169
|
+
} catch (NumberFormatException | IOException e) {//"finish"以外の文字が入力されたときはこちらへ
|
172
|
-
|
170
|
+
|
173
|
-
|
171
|
+
System.out.println("Could you enter the number?");
|
174
|
-
|
172
|
+
|
175
|
-
|
173
|
+
System.out.println("Your Paramaters cannot understand.");
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
}if(a==0) {x1=x2=(-c)/b;}
|
180
|
-
|
181
|
-
else {
|
182
|
-
|
183
|
-
if(d<0) {d=b*b-4*a*c;
|
184
|
-
|
185
|
-
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
186
|
-
|
187
|
-
}else {
|
188
|
-
|
189
|
-
x1 =(-b + Math.sqrt(d))/(2*a);
|
190
|
-
|
191
|
-
x2 =(-b - Math.sqrt(d))/(2*a);
|
192
|
-
|
193
|
-
System.out.println("x1="+ x1);
|
194
|
-
|
195
|
-
System.out.println("x2="+ x2);
|
196
174
|
|
197
175
|
}
|
198
176
|
|
177
|
+
if (a == 0) {
|
178
|
+
|
179
|
+
x1 = x2 = (-c) / b;
|
180
|
+
|
181
|
+
} else {
|
182
|
+
|
183
|
+
if (d < 0) {
|
184
|
+
|
185
|
+
d = b * b - 4 * a * c;
|
186
|
+
|
187
|
+
System.out.println("There is no solution because the discriminant is negative. D=" + d);
|
188
|
+
|
189
|
+
} else {
|
190
|
+
|
191
|
+
x1 = (-b + Math.sqrt(d)) / (2 * a);
|
192
|
+
|
193
|
+
x2 = (-b - Math.sqrt(d)) / (2 * a);
|
194
|
+
|
195
|
+
System.out.println("x1=" + x1);
|
196
|
+
|
197
|
+
System.out.println("x2=" + x2);
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
return line;
|
204
|
+
|
199
205
|
}
|
200
206
|
|
201
|
-
return line;
|
202
|
-
|
203
|
-
}
|
207
|
+
}
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
208
|
+
|
209
|
+
|
212
210
|
|
213
211
|
```
|
214
212
|
|
6
変更しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,180 +68,152 @@
|
|
68
68
|
|
69
69
|
### 発生している問題
|
70
70
|
|
71
|
-
|
71
|
+
キーボード入力した数字をa,b,cとして認識させたいです。。
|
72
72
|
|
73
73
|
どこにどのプログラムや式を入れ込めばいいのか見当がつきません。
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
+
###今自分の中でわかっていること
|
78
|
+
|
79
|
+
・キーボードで入力した数字を順番にa,b,cと置きたいが、それの方法が分からない。
|
80
|
+
|
81
|
+
例)1,-2,-3とキーボードから入力したら、それぞれをa(=1),b(=-2),c(=3)として認識させたい。
|
82
|
+
|
83
|
+
・数字を入力した後、計算式のところに行ってくれるようにする方法が分からない。
|
84
|
+
|
85
|
+
・public static String getInput(){}に問題があることは認識しているのですが、全体的に意味不明になっており、どこから手を付ければいいかわからない状態です。
|
86
|
+
|
87
|
+
|
88
|
+
|
77
|
-
###
|
89
|
+
### 該当のソースコード
|
78
|
-
|
79
|
-
|
80
90
|
|
81
91
|
```java
|
82
92
|
|
93
|
+
import java.io.BufferedReader;
|
94
|
+
|
95
|
+
import java.io.IOException;
|
96
|
+
|
97
|
+
import java.io.InputStreamReader;
|
98
|
+
|
99
|
+
import java.util.Scanner;
|
100
|
+
|
101
|
+
public class nijikannsuu {
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
public static void main(String[] args) {
|
106
|
+
|
107
|
+
String line="";
|
108
|
+
|
109
|
+
double a=0,b=0,c=0;
|
110
|
+
|
111
|
+
boolean terminate = false;
|
112
|
+
|
113
|
+
while(true) {
|
114
|
+
|
115
|
+
line=getInput();
|
116
|
+
|
117
|
+
if(line.equals("finish")) {
|
118
|
+
|
119
|
+
System.out.println("Thanks you for using this system.");
|
120
|
+
|
121
|
+
return;
|
122
|
+
|
123
|
+
}else {
|
124
|
+
|
125
|
+
try {
|
126
|
+
|
127
|
+
String[] abc=line.split(",");
|
128
|
+
|
129
|
+
a=Double.parseDouble(abc[0]);
|
130
|
+
|
131
|
+
b=Double.parseDouble(abc[1]);
|
132
|
+
|
133
|
+
c=Double.parseDouble(abc[2]);
|
134
|
+
|
135
|
+
} catch(NumberFormatException e) {
|
136
|
+
|
137
|
+
System.out.println("Your Paramaters cannot understand.");
|
138
|
+
|
139
|
+
break;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
public static String getInput() {
|
152
|
+
|
153
|
+
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
154
|
+
|
155
|
+
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
156
|
+
|
157
|
+
String line = null;
|
158
|
+
|
159
|
+
Scanner sc=new Scanner(System.in);
|
160
|
+
|
161
|
+
System.out.println("Please Input: a,b,c");
|
162
|
+
|
163
|
+
try {
|
164
|
+
|
165
|
+
for(int i=0; i<3; i++) {
|
166
|
+
|
167
|
+
line = reader.readLine();//ここでキーボード入力を行えるようにする?
|
168
|
+
|
169
|
+
System.out.println("line="+a+", "+b+", "+c);//上で入力した数字をa,b,cとして認識させたい。
|
170
|
+
|
171
|
+
}}catch(NumberFormatException | IOException e) {
|
172
|
+
|
173
|
+
System.out.println("Could you enter the number?");
|
174
|
+
|
175
|
+
System.out.println("Please try again!");
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
}if(a==0) {x1=x2=(-c)/b;}
|
180
|
+
|
181
|
+
else {
|
182
|
+
|
183
|
+
if(d<0) {d=b*b-4*a*c;
|
184
|
+
|
83
|
-
|
185
|
+
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
186
|
+
|
84
|
-
|
187
|
+
}else {
|
188
|
+
|
189
|
+
x1 =(-b + Math.sqrt(d))/(2*a);
|
190
|
+
|
191
|
+
x2 =(-b - Math.sqrt(d))/(2*a);
|
192
|
+
|
193
|
+
System.out.println("x1="+ x1);
|
194
|
+
|
85
|
-
|
195
|
+
System.out.println("x2="+ x2);
|
196
|
+
|
86
|
-
|
197
|
+
}
|
198
|
+
|
87
|
-
|
199
|
+
}
|
200
|
+
|
201
|
+
return line;
|
202
|
+
|
203
|
+
}}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
88
212
|
|
89
213
|
```
|
90
214
|
|
91
215
|
|
92
216
|
|
93
|
-
###今自分の中でわかっていること
|
94
|
-
|
95
|
-
・キーボードで入力した数字を順番にa,b,cと置きたいが、それの方法が分からない。
|
96
|
-
|
97
|
-
例)1,-2,-3とキーボードから入力したら、それぞれをa(=1),b(=-2),c(=3)として認識させたい。
|
98
|
-
|
99
|
-
・数字を入力した後、計算式のところに行ってくれるようにする方法が分からない。
|
100
|
-
|
101
|
-
・public static String getInput(){}に問題があることは認識しているのですが、全体的に意味不明になっており、どこから手を付ければいいかわからない状態です。
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
### 該当のソースコード
|
106
|
-
|
107
|
-
```java
|
108
|
-
|
109
|
-
import java.io.BufferedReader;
|
110
|
-
|
111
|
-
import java.io.IOException;
|
112
|
-
|
113
|
-
import java.util.Scanner;
|
114
|
-
|
115
|
-
import java.io.InputStreamReader;
|
116
|
-
|
117
|
-
public class nijikannsuu {
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
public static void main(String[] args) {
|
122
|
-
|
123
|
-
String line="";
|
124
|
-
|
125
|
-
double a=0,b=0,c=0;
|
126
|
-
|
127
|
-
boolean terminate = false;
|
128
|
-
|
129
|
-
while(true) {
|
130
|
-
|
131
|
-
line=getInput();
|
132
|
-
|
133
|
-
if(line.equals("finish")) {
|
134
|
-
|
135
|
-
System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
|
136
|
-
|
137
|
-
return;
|
138
|
-
|
139
|
-
}else
|
140
|
-
|
141
|
-
try {
|
142
|
-
|
143
|
-
String[] abc=line.split(",");
|
144
|
-
|
145
|
-
a=Double.parseDouble(abc[0]);
|
146
|
-
|
147
|
-
b=Double.parseDouble(abc[1]);
|
148
|
-
|
149
|
-
c=Double.parseDouble(abc[2]);
|
150
|
-
|
151
|
-
}catch(NumberFormatException e) {
|
152
|
-
|
153
|
-
System.out.println("Your Paramaters cannot understand.");
|
154
|
-
|
155
|
-
break;
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
public static String getInput() {
|
168
|
-
|
169
|
-
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
170
|
-
|
171
|
-
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
172
|
-
|
173
|
-
String line;
|
174
|
-
|
175
|
-
int s[]=new int[5];
|
176
|
-
|
177
|
-
Scanner sc=new Scanner(System.in);
|
178
|
-
|
179
|
-
for(int i=0;i<s.length; i++) {
|
180
|
-
|
181
|
-
System.out.println("Please Input: a,b,c");
|
182
|
-
|
183
|
-
s[i]=sc.nextInt();
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
try {
|
188
|
-
|
189
|
-
for(int i=0; i<s.length; i++) {
|
190
|
-
|
191
|
-
line = reader.readLine();
|
192
|
-
|
193
|
-
System.out.printf("s[%2d]=%d\n",i,s[i]);
|
194
|
-
|
195
|
-
System.out.println("line="+a+", "+b+", "+c);
|
196
|
-
|
197
|
-
}catch(NumberFormatException e) {
|
198
|
-
|
199
|
-
System.out.println("Could you enter the number?");
|
200
|
-
|
201
|
-
System.out.println("Please try again!");
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
if(a==0) {x1=x2=(-c)/b; }
|
210
|
-
|
211
|
-
else {
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
d=b*b-4*a*c;
|
216
|
-
|
217
|
-
if(d<0) {
|
218
|
-
|
219
|
-
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
220
|
-
|
221
|
-
return;
|
222
|
-
|
223
|
-
}else {
|
224
|
-
|
225
|
-
x1 =(-b + Math.sqrt(d))/(2*a);
|
226
|
-
|
227
|
-
x2 =(-b - Math.sqrt(d))/(2*a);
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
System.out.println("x1="+ x1);
|
234
|
-
|
235
|
-
System.out.println("x2="+ x2);
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
```
|
242
|
-
|
243
|
-
|
244
|
-
|
245
217
|
|
246
218
|
|
247
219
|
### 試したこと
|
5
関数をひとまず消去
test
CHANGED
File without changes
|
test
CHANGED
@@ -158,88 +158,86 @@
|
|
158
158
|
|
159
159
|
}
|
160
160
|
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
public static String getInput() {
|
168
|
+
|
169
|
+
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
170
|
+
|
171
|
+
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
172
|
+
|
173
|
+
String line;
|
174
|
+
|
175
|
+
int s[]=new int[5];
|
176
|
+
|
177
|
+
Scanner sc=new Scanner(System.in);
|
178
|
+
|
179
|
+
for(int i=0;i<s.length; i++) {
|
180
|
+
|
181
|
+
System.out.println("Please Input: a,b,c");
|
182
|
+
|
183
|
+
s[i]=sc.nextInt();
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
try {
|
188
|
+
|
189
|
+
for(int i=0; i<s.length; i++) {
|
190
|
+
|
191
|
+
line = reader.readLine();
|
192
|
+
|
193
|
+
System.out.printf("s[%2d]=%d\n",i,s[i]);
|
194
|
+
|
195
|
+
System.out.println("line="+a+", "+b+", "+c);
|
196
|
+
|
197
|
+
}catch(NumberFormatException e) {
|
198
|
+
|
199
|
+
System.out.println("Could you enter the number?");
|
200
|
+
|
201
|
+
System.out.println("Please try again!");
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
}
|
206
|
+
|
161
207
|
}
|
162
208
|
|
163
|
-
|
209
|
+
if(a==0) {x1=x2=(-c)/b; }
|
210
|
+
|
211
|
+
else {
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
d=b*b-4*a*c;
|
216
|
+
|
217
|
+
if(d<0) {
|
218
|
+
|
219
|
+
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
220
|
+
|
221
|
+
return;
|
222
|
+
|
223
|
+
}else {
|
224
|
+
|
225
|
+
x1 =(-b + Math.sqrt(d))/(2*a);
|
226
|
+
|
227
|
+
x2 =(-b - Math.sqrt(d))/(2*a);
|
164
228
|
|
165
229
|
}
|
166
230
|
|
167
|
-
|
168
|
-
|
169
|
-
public static String getInput() {
|
170
|
-
|
171
|
-
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
172
|
-
|
173
|
-
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
174
|
-
|
175
|
-
String line;
|
176
|
-
|
177
|
-
int s[]=new int[5];
|
178
|
-
|
179
|
-
Scanner sc=new Scanner(System.in);
|
180
|
-
|
181
|
-
for(int i=0;i<s.length; i++) {
|
182
|
-
|
183
|
-
System.out.println("Please Input: a,b,c");
|
184
|
-
|
185
|
-
s[i]=sc.nextInt();
|
186
|
-
|
187
|
-
|
231
|
+
}
|
188
|
-
|
189
|
-
|
232
|
+
|
190
|
-
|
191
|
-
|
233
|
+
System.out.println("x1="+ x1);
|
192
|
-
|
193
|
-
|
234
|
+
|
194
|
-
|
195
|
-
|
235
|
+
System.out.println("x2="+ x2);
|
196
|
-
|
197
|
-
|
236
|
+
|
198
|
-
|
199
|
-
}catch(NumberFormatException e) {
|
200
|
-
|
201
|
-
System.out.println("Could you enter the number?");
|
202
|
-
|
203
|
-
System.out.println("Please try again!");
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
237
|
+
}
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
if(a==0) {x1=x2=(-c)/b; }
|
212
|
-
|
213
|
-
else {
|
214
238
|
|
215
239
|
|
216
240
|
|
217
|
-
d=b*b-4*a*c;
|
218
|
-
|
219
|
-
if(d<0) {
|
220
|
-
|
221
|
-
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
222
|
-
|
223
|
-
return;
|
224
|
-
|
225
|
-
}else {
|
226
|
-
|
227
|
-
x1 =(-b + Math.sqrt(d))/(2*a);
|
228
|
-
|
229
|
-
x2 =(-b - Math.sqrt(d))/(2*a);
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
System.out.println("x1="+ x1);
|
236
|
-
|
237
|
-
System.out.println("x2="+ x2);
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
241
|
```
|
244
242
|
|
245
243
|
|
4
修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -120,8 +120,6 @@
|
|
120
120
|
|
121
121
|
public static void main(String[] args) {
|
122
122
|
|
123
|
-
// TODO 自動生成されたメソッド・スタブ
|
124
|
-
|
125
123
|
String line="";
|
126
124
|
|
127
125
|
double a=0,b=0,c=0;
|
@@ -214,12 +212,10 @@
|
|
214
212
|
|
215
213
|
else {
|
216
214
|
|
217
|
-
|
215
|
+
|
218
216
|
|
219
217
|
d=b*b-4*a*c;
|
220
218
|
|
221
|
-
//if D is smaller than Zero, no real solutions.
|
222
|
-
|
223
219
|
if(d<0) {
|
224
220
|
|
225
221
|
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
@@ -228,8 +224,6 @@
|
|
228
224
|
|
229
225
|
}else {
|
230
226
|
|
231
|
-
// compute the two solutions.
|
232
|
-
|
233
227
|
x1 =(-b + Math.sqrt(d))/(2*a);
|
234
228
|
|
235
229
|
x2 =(-b - Math.sqrt(d))/(2*a);
|
@@ -238,8 +232,6 @@
|
|
238
232
|
|
239
233
|
}
|
240
234
|
|
241
|
-
//disaplay the solutions.
|
242
|
-
|
243
235
|
System.out.println("x1="+ x1);
|
244
236
|
|
245
237
|
System.out.println("x2="+ x2);
|
3
字下げをしていませんでした。
test
CHANGED
File without changes
|
test
CHANGED
@@ -118,125 +118,135 @@
|
|
118
118
|
|
119
119
|
|
120
120
|
|
121
|
-
public static void main(String[] args) {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
b
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
l
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
a=
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
sol
|
152
|
-
|
153
|
-
}catch(NumberFormatException e) {
|
154
|
-
|
155
|
-
System.out.println("Your Paramaters cannot understand.");
|
156
|
-
|
157
|
-
break;
|
121
|
+
public static void main(String[] args) {
|
122
|
+
|
123
|
+
// TODO 自動生成されたメソッド・スタブ
|
124
|
+
|
125
|
+
String line="";
|
126
|
+
|
127
|
+
double a=0,b=0,c=0;
|
128
|
+
|
129
|
+
boolean terminate = false;
|
130
|
+
|
131
|
+
while(true) {
|
132
|
+
|
133
|
+
line=getInput();
|
134
|
+
|
135
|
+
if(line.equals("finish")) {
|
136
|
+
|
137
|
+
System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
|
138
|
+
|
139
|
+
return;
|
140
|
+
|
141
|
+
}else
|
142
|
+
|
143
|
+
try {
|
144
|
+
|
145
|
+
String[] abc=line.split(",");
|
146
|
+
|
147
|
+
a=Double.parseDouble(abc[0]);
|
148
|
+
|
149
|
+
b=Double.parseDouble(abc[1]);
|
150
|
+
|
151
|
+
c=Double.parseDouble(abc[2]);
|
152
|
+
|
153
|
+
}catch(NumberFormatException e) {
|
154
|
+
|
155
|
+
System.out.println("Your Paramaters cannot understand.");
|
156
|
+
|
157
|
+
break;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
public static String getInput() {
|
172
|
+
|
173
|
+
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
174
|
+
|
175
|
+
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
176
|
+
|
177
|
+
String line;
|
178
|
+
|
179
|
+
int s[]=new int[5];
|
180
|
+
|
181
|
+
Scanner sc=new Scanner(System.in);
|
182
|
+
|
183
|
+
for(int i=0;i<s.length; i++) {
|
184
|
+
|
185
|
+
System.out.println("Please Input: a,b,c");
|
186
|
+
|
187
|
+
s[i]=sc.nextInt();
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
try {
|
192
|
+
|
193
|
+
for(int i=0; i<s.length; i++) {
|
194
|
+
|
195
|
+
line = reader.readLine();
|
196
|
+
|
197
|
+
System.out.printf("s[%2d]=%d\n",i,s[i]);
|
198
|
+
|
199
|
+
System.out.println("line="+a+", "+b+", "+c);
|
200
|
+
|
201
|
+
}catch(NumberFormatException e) {
|
202
|
+
|
203
|
+
System.out.println("Could you enter the number?");
|
204
|
+
|
205
|
+
System.out.println("Please try again!");
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
if(a==0) {x1=x2=(-c)/b; }
|
214
|
+
|
215
|
+
else {
|
216
|
+
|
217
|
+
//compute the discriminant/
|
218
|
+
|
219
|
+
d=b*b-4*a*c;
|
220
|
+
|
221
|
+
//if D is smaller than Zero, no real solutions.
|
222
|
+
|
223
|
+
if(d<0) {
|
224
|
+
|
225
|
+
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
226
|
+
|
227
|
+
return;
|
228
|
+
|
229
|
+
}else {
|
230
|
+
|
231
|
+
// compute the two solutions.
|
232
|
+
|
233
|
+
x1 =(-b + Math.sqrt(d))/(2*a);
|
234
|
+
|
235
|
+
x2 =(-b - Math.sqrt(d))/(2*a);
|
236
|
+
|
237
|
+
}
|
158
238
|
|
159
239
|
}
|
160
240
|
|
241
|
+
//disaplay the solutions.
|
242
|
+
|
243
|
+
System.out.println("x1="+ x1);
|
244
|
+
|
245
|
+
System.out.println("x2="+ x2);
|
246
|
+
|
161
247
|
}
|
162
248
|
|
163
|
-
|
249
|
+
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
public static String getInput() {
|
168
|
-
|
169
|
-
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
170
|
-
|
171
|
-
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
172
|
-
|
173
|
-
String line;
|
174
|
-
|
175
|
-
int s[]=new int[5];
|
176
|
-
|
177
|
-
Scanner sc=new Scanner(System.in);
|
178
|
-
|
179
|
-
for(int i=0;i<s.length; i++) {
|
180
|
-
|
181
|
-
System.out.println("Please Input: a,b,c");
|
182
|
-
|
183
|
-
s[i]=sc.nextInt();
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
try {
|
188
|
-
|
189
|
-
for(int i=0; i<s.length; i++) {
|
190
|
-
|
191
|
-
line = reader.readLine();
|
192
|
-
|
193
|
-
System.out.printf("s[%2d]=%d\n",i,s[i]);
|
194
|
-
|
195
|
-
System.out.println("line="+a+", "+b+", "+c);
|
196
|
-
|
197
|
-
}catch(NumberFormatException e) {
|
198
|
-
|
199
|
-
System.out.println("Could you enter the number?");
|
200
|
-
|
201
|
-
System.out.println("Please try again!");
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
if(a==0) {x1=x2=(-c)/b; }
|
208
|
-
|
209
|
-
else {
|
210
|
-
|
211
|
-
d=b*b-4*a*c;
|
212
|
-
|
213
|
-
//if D is smaller than Zero, no real solutions.
|
214
|
-
|
215
|
-
if(d<0) {
|
216
|
-
|
217
|
-
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
218
|
-
|
219
|
-
return;
|
220
|
-
|
221
|
-
}else {
|
222
|
-
|
223
|
-
x1 =(-b + Math.sqrt(d))/(2*a);
|
224
|
-
|
225
|
-
x2 =(-b - Math.sqrt(d))/(2*a);
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
//disaplay the solutions.
|
232
|
-
|
233
|
-
System.out.println("x1="+ x1);
|
234
|
-
|
235
|
-
System.out.println("x2="+ x2);
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
|
240
250
|
|
241
251
|
```
|
242
252
|
|
2
エラーメッセージ 抜けていた部分がありました 失礼いたしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -82,9 +82,7 @@
|
|
82
82
|
|
83
83
|
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
メソッド solveEq(double, double, double) は型 nijikannsuu で未定義です at nijikannsuu.main(Finalreport1.java:23)
|
88
86
|
|
89
87
|
|
90
88
|
|
1
大変失礼いたしました。申し訳ございません。こちらでよろしいでしょうか?
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,6 +76,10 @@
|
|
76
76
|
|
77
77
|
###エラーメッセージ
|
78
78
|
|
79
|
+
|
80
|
+
|
81
|
+
```java
|
82
|
+
|
79
83
|
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
|
80
84
|
|
81
85
|
|
@@ -84,6 +88,10 @@
|
|
84
88
|
|
85
89
|
|
86
90
|
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
|
87
95
|
###今自分の中でわかっていること
|
88
96
|
|
89
97
|
・キーボードで入力した数字を順番にa,b,cと置きたいが、それの方法が分からない。
|
@@ -98,6 +106,8 @@
|
|
98
106
|
|
99
107
|
### 該当のソースコード
|
100
108
|
|
109
|
+
```java
|
110
|
+
|
101
111
|
import java.io.BufferedReader;
|
102
112
|
|
103
113
|
import java.io.IOException;
|
@@ -110,113 +120,113 @@
|
|
110
120
|
|
111
121
|
|
112
122
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
123
|
+
public static void main(String[] args) {
|
124
|
+
|
125
|
+
String line="";
|
126
|
+
|
127
|
+
double a=0,b=0,c=0;
|
128
|
+
|
129
|
+
boolean terminate = false;
|
130
|
+
|
131
|
+
while(true) {
|
132
|
+
|
133
|
+
line=getInput();
|
134
|
+
|
135
|
+
if(line.equals("finish")) {
|
136
|
+
|
137
|
+
System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
|
138
|
+
|
139
|
+
return;
|
140
|
+
|
141
|
+
}else
|
142
|
+
|
143
|
+
try {
|
144
|
+
|
145
|
+
String[] abc=line.split(",");
|
146
|
+
|
147
|
+
a=Double.parseDouble(abc[0]);
|
148
|
+
|
149
|
+
b=Double.parseDouble(abc[1]);
|
150
|
+
|
151
|
+
c=Double.parseDouble(abc[2]);
|
152
|
+
|
153
|
+
solveEq(a,b,c);
|
154
|
+
|
155
|
+
}catch(NumberFormatException e) {
|
156
|
+
|
157
|
+
System.out.println("Your Paramaters cannot understand.");
|
158
|
+
|
159
|
+
break;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
public static String getInput() {
|
170
|
+
|
171
|
+
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
|
172
|
+
|
173
|
+
double a=0,b=0,c=0,d=0,x1=0,x2=0;
|
174
|
+
|
175
|
+
String line;
|
176
|
+
|
177
|
+
int s[]=new int[5];
|
178
|
+
|
179
|
+
Scanner sc=new Scanner(System.in);
|
180
|
+
|
181
|
+
for(int i=0;i<s.length; i++) {
|
182
|
+
|
183
|
+
System.out.println("Please Input: a,b,c");
|
184
|
+
|
185
|
+
s[i]=sc.nextInt();
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
try {
|
190
|
+
|
191
|
+
for(int i=0; i<s.length; i++) {
|
192
|
+
|
193
|
+
line = reader.readLine();
|
194
|
+
|
195
|
+
System.out.printf("s[%2d]=%d\n",i,s[i]);
|
196
|
+
|
197
|
+
System.out.println("line="+a+", "+b+", "+c);
|
198
|
+
|
199
|
+
}catch(NumberFormatException e) {
|
200
|
+
|
201
|
+
System.out.println("Could you enter the number?");
|
202
|
+
|
203
|
+
System.out.println("Please try again!");
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
if(a==0) {x1=x2=(-c)/b; }
|
210
|
+
|
211
|
+
else {
|
212
|
+
|
213
|
+
d=b*b-4*a*c;
|
214
|
+
|
215
|
+
//if D is smaller than Zero, no real solutions.
|
216
|
+
|
217
|
+
if(d<0) {
|
218
|
+
|
219
|
+
System.out.println("There is no solution because the discriminant is negative. D="+d);
|
220
|
+
|
221
|
+
return;
|
222
|
+
|
223
|
+
}else {
|
224
|
+
|
225
|
+
x1 =(-b + Math.sqrt(d))/(2*a);
|
226
|
+
|
227
|
+
x2 =(-b - Math.sqrt(d))/(2*a);
|
228
|
+
|
229
|
+
}
|
220
230
|
|
221
231
|
}
|
222
232
|
|
@@ -228,7 +238,13 @@
|
|
228
238
|
|
229
239
|
}
|
230
240
|
|
241
|
+
|
242
|
+
|
231
|
-
|
243
|
+
```
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
232
248
|
|
233
249
|
### 試したこと
|
234
250
|
|