teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

8

変更しました

2020/07/10 21:03

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -56,6 +56,7 @@
56
56
  double a = 0, b = 0, c = 0;
57
57
  boolean terminate = false;
58
58
  while (true) {
59
+
59
60
  line = getInput();
60
61
  if (line.equals("finish")) {
61
62
  System.out.println("Thanks you for using this system.");
@@ -76,13 +77,14 @@
76
77
  try {
77
78
  line = reader.readLine();
78
79
  String[] abc = line.split(",");
80
+ if (line.equals("finish")) {
81
+ return "finish";
82
+ } else
79
- a = Double.parseDouble(abc[0]);
83
+ a = Double.parseDouble(abc[0]);
80
84
  b = Double.parseDouble(abc[1]);
81
85
  c = Double.parseDouble(abc[2]);
82
86
  System.out.println("line=" + a + ", " + b + ", " + c);
83
- } catch (String q) {//ここで"finish"をキャッチしたいです。
84
- System.out.printf("");
85
- } catch (NumberFormatException | IOException e) {//"finish"以外の文字が入力されたときはこちらへ
87
+ } catch (NumberFormatException | IOException e) {//
86
88
  System.out.println("Could you enter the number?");
87
89
  System.out.println("Your Paramaters cannot understand.");
88
90
  }

7

修正しました。

2020/07/10 21:03

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -48,62 +48,61 @@
48
48
  import java.io.IOException;
49
49
  import java.io.InputStreamReader;
50
50
  import java.util.Scanner;
51
+
51
52
  public class nijikannsuu {
52
53
 
53
54
  public static void main(String[] args) {
54
- String line="";
55
+ String line = "";
55
- double a=0,b=0,c=0;
56
+ double a = 0, b = 0, c = 0;
56
57
  boolean terminate = false;
57
- while(true) {
58
+ while (true) {
58
- line=getInput();
59
+ line = getInput();
59
- if(line.equals("finish")) {
60
+ if (line.equals("finish")) {
60
61
  System.out.println("Thanks you for using this system.");
61
62
  return;
62
- }else {
63
+ } else {
63
- try {
64
+
64
- String[] abc=line.split(",");
65
- a=Double.parseDouble(abc[0]);
66
- b=Double.parseDouble(abc[1]);
67
- c=Double.parseDouble(abc[2]);
68
- } catch(NumberFormatException e) {
69
- System.out.println("Your Paramaters cannot understand.");
70
- break;
71
65
  }
72
66
  }
73
- }
74
67
  }
75
68
 
76
69
  public static String getInput() {
77
- BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
70
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
78
- double a=0,b=0,c=0,d=0,x1=0,x2=0;
71
+ double a = 0, b = 0, c = 0, d = 0, x1 = 0, x2 = 0;
79
72
  String line = null;
80
- Scanner sc=new Scanner(System.in);
73
+ Scanner sc = new Scanner(System.in);
81
- System.out.println("Please Input: a,b,c");
74
+ System.out.println("Please Input: a,b,c");
75
+ String q = "finish";
82
76
  try {
83
- for(int i=0; i<3; i++) {
84
- line = reader.readLine();//ここでキーボード入力を行えるようにする?
77
+ line = reader.readLine();
78
+ String[] abc = line.split(",");
79
+ a = Double.parseDouble(abc[0]);
80
+ b = Double.parseDouble(abc[1]);
81
+ c = Double.parseDouble(abc[2]);
85
- System.out.println("line="+a+", "+b+", "+c);//上で入力した数字をa,b,cとして認識させたい。
82
+ System.out.println("line=" + a + ", " + b + ", " + c);
83
+ } catch (String q) {//ここで"finish"をキャッチしたいです。
84
+ System.out.printf("");
86
- }}catch(NumberFormatException | IOException e) {
85
+ } catch (NumberFormatException | IOException e) {//"finish"以外の文字が入力されたときはこちらへ
87
- System.out.println("Could you enter the number?");
86
+ System.out.println("Could you enter the number?");
88
- System.out.println("Please try again!");
87
+ System.out.println("Your Paramaters cannot understand.");
89
-
90
- }if(a==0) {x1=x2=(-c)/b;}
91
- else {
92
- if(d<0) {d=b*b-4*a*c;
93
- System.out.println("There is no solution because the discriminant is negative. D="+d);
94
- }else {
95
- x1 =(-b + Math.sqrt(d))/(2*a);
96
- x2 =(-b - Math.sqrt(d))/(2*a);
97
- System.out.println("x1="+ x1);
98
- System.out.println("x2="+ x2);
99
88
  }
89
+ if (a == 0) {
90
+ x1 = x2 = (-c) / b;
91
+ } else {
92
+ if (d < 0) {
93
+ d = b * b - 4 * a * c;
94
+ System.out.println("There is no solution because the discriminant is negative. D=" + d);
95
+ } else {
96
+ x1 = (-b + Math.sqrt(d)) / (2 * a);
97
+ x2 = (-b - Math.sqrt(d)) / (2 * a);
98
+ System.out.println("x1=" + x1);
99
+ System.out.println("x2=" + x2);
100
+ }
101
+ }
102
+ return line;
100
103
  }
101
- return line;
102
- }}
104
+ }
103
105
 
104
-
105
-
106
-
107
106
  ```
108
107
 
109
108
 

6

変更しました

2020/07/08 10:37

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -33,17 +33,9 @@
33
33
 
34
34
 
35
35
  ### 発生している問題
36
- プログラムが起動いです。
36
+ キーボード入力た数字をa,b,cとして認識させたいです。
37
37
  どこにどのプログラムや式を入れ込めばいいのか見当がつきません。
38
38
 
39
- ###エラーメッセージ
40
-
41
- ```java
42
- Exception in thread "main" java.lang.Error: Unresolved compilation problem:
43
- メソッド solveEq(double, double, double) は型 nijikannsuu で未定義です at nijikannsuu.main(Finalreport1.java:23)
44
-
45
- ```
46
-
47
39
  ###今自分の中でわかっていること
48
40
  ・キーボードで入力した数字を順番にa,b,cと置きたいが、それの方法が分からない。
49
41
  例)1,-2,-3とキーボードから入力したら、それぞれをa(=1),b(=-2),c(=3)として認識させたい。
@@ -54,8 +46,8 @@
54
46
  ```java
55
47
  import java.io.BufferedReader;
56
48
  import java.io.IOException;
49
+ import java.io.InputStreamReader;
57
50
  import java.util.Scanner;
58
- import java.io.InputStreamReader;
59
51
  public class nijikannsuu {
60
52
 
61
53
  public static void main(String[] args) {
@@ -65,59 +57,53 @@
65
57
  while(true) {
66
58
  line=getInput();
67
59
  if(line.equals("finish")) {
68
- System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
60
+ System.out.println("Thanks you for using this system.");
69
61
  return;
70
- }else
62
+ }else {
71
63
  try {
72
64
  String[] abc=line.split(",");
73
65
  a=Double.parseDouble(abc[0]);
74
66
  b=Double.parseDouble(abc[1]);
75
67
  c=Double.parseDouble(abc[2]);
76
- }catch(NumberFormatException e) {
68
+ } catch(NumberFormatException e) {
77
69
  System.out.println("Your Paramaters cannot understand.");
78
70
  break;
79
71
  }
80
72
  }
81
- }
73
+ }
82
-
74
+ }
83
75
 
84
76
  public static String getInput() {
85
77
  BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
86
78
  double a=0,b=0,c=0,d=0,x1=0,x2=0;
87
- String line;
79
+ String line = null;
88
- int s[]=new int[5];
89
80
  Scanner sc=new Scanner(System.in);
90
- for(int i=0;i<s.length; i++) {
91
81
  System.out.println("Please Input: a,b,c");
92
- s[i]=sc.nextInt();
93
- }
94
82
  try {
95
- for(int i=0; i<s.length; i++) {
83
+ for(int i=0; i<3; i++) {
96
- line = reader.readLine();
84
+ line = reader.readLine();//ここでキーボード入力を行えるようにする?
97
- System.out.printf("s[%2d]=%d\n",i,s[i]);
98
- System.out.println("line="+a+", "+b+", "+c);
85
+ System.out.println("line="+a+", "+b+", "+c);//上で入力した数字をa,b,cとして認識させたい。
99
- }catch(NumberFormatException e) {
86
+ }}catch(NumberFormatException | IOException e) {
100
87
  System.out.println("Could you enter the number?");
101
88
  System.out.println("Please try again!");
89
+
102
-
90
+ }if(a==0) {x1=x2=(-c)/b;}
91
+ else {
92
+ if(d<0) {d=b*b-4*a*c;
93
+ System.out.println("There is no solution because the discriminant is negative. D="+d);
94
+ }else {
95
+ x1 =(-b + Math.sqrt(d))/(2*a);
96
+ x2 =(-b - Math.sqrt(d))/(2*a);
97
+ System.out.println("x1="+ x1);
98
+ System.out.println("x2="+ x2);
103
- }
99
+ }
104
100
  }
105
- if(a==0) {x1=x2=(-c)/b; }
106
- else {
101
+ return line;
102
+ }}
103
+
104
+
105
+
107
106
 
108
- d=b*b-4*a*c;
109
- if(d<0) {
110
- System.out.println("There is no solution because the discriminant is negative. D="+d);
111
- return;
112
- }else {
113
- x1 =(-b + Math.sqrt(d))/(2*a);
114
- x2 =(-b - Math.sqrt(d))/(2*a);
115
- }
116
-    }
117
-     System.out.println("x1="+ x1);
118
-     System.out.println("x2="+ x2);
119
- }
120
-
121
107
  ```
122
108
 
123
109
 

5

関数をひとまず消去

2020/07/08 05:56

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -78,9 +78,8 @@
78
78
  break;
79
79
  }
80
80
  }
81
- }
81
+ }
82
82
 
83
- }
84
83
 
85
84
  public static String getInput() {
86
85
  BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
@@ -114,10 +113,10 @@
114
113
  x1 =(-b + Math.sqrt(d))/(2*a);
115
114
  x2 =(-b - Math.sqrt(d))/(2*a);
116
115
  }
116
+    }
117
+     System.out.println("x1="+ x1);
118
+     System.out.println("x2="+ x2);
117
119
  }
118
- System.out.println("x1="+ x1);
119
- System.out.println("x2="+ x2);
120
- }
121
120
 
122
121
  ```
123
122
 

4

修正しました

2020/07/07 14:47

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -59,7 +59,6 @@
59
59
  public class nijikannsuu {
60
60
 
61
61
  public static void main(String[] args) {
62
- // TODO 自動生成されたメソッド・スタブ
63
62
  String line="";
64
63
  double a=0,b=0,c=0;
65
64
  boolean terminate = false;
@@ -106,19 +105,16 @@
106
105
  }
107
106
  if(a==0) {x1=x2=(-c)/b; }
108
107
  else {
109
- //compute the discriminant/
108
+
110
109
  d=b*b-4*a*c;
111
- //if D is smaller than Zero, no real solutions.
112
110
  if(d<0) {
113
111
  System.out.println("There is no solution because the discriminant is negative. D="+d);
114
112
  return;
115
113
  }else {
116
- // compute the two solutions.
117
114
  x1 =(-b + Math.sqrt(d))/(2*a);
118
115
  x2 =(-b - Math.sqrt(d))/(2*a);
119
116
  }
120
117
  }
121
- //disaplay the solutions.
122
118
  System.out.println("x1="+ x1);
123
119
  System.out.println("x2="+ x2);
124
120
  }

3

字下げをしていませんでした。

2020/07/07 14:41

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -58,66 +58,71 @@
58
58
  import java.io.InputStreamReader;
59
59
  public class nijikannsuu {
60
60
 
61
- public static void main(String[] args) {
61
+ public static void main(String[] args) {
62
+ // TODO 自動生成されたメソッド・スタブ
62
- String line="";
63
+ String line="";
63
- double a=0,b=0,c=0;
64
+ double a=0,b=0,c=0;
64
- boolean terminate = false;
65
+ boolean terminate = false;
65
- while(true) {
66
+ while(true) {
66
- line=getInput();
67
+ line=getInput();
67
- if(line.equals("finish")) {
68
+ if(line.equals("finish")) {
68
- System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
69
+ System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
69
- return;
70
+ return;
70
- }else
71
+ }else
71
- try {
72
+ try {
72
- String[] abc=line.split(",");
73
+ String[] abc=line.split(",");
73
- a=Double.parseDouble(abc[0]);
74
+ a=Double.parseDouble(abc[0]);
74
- b=Double.parseDouble(abc[1]);
75
+ b=Double.parseDouble(abc[1]);
75
- c=Double.parseDouble(abc[2]);
76
+ c=Double.parseDouble(abc[2]);
76
- solveEq(a,b,c);
77
- }catch(NumberFormatException e) {
77
+ }catch(NumberFormatException e) {
78
- System.out.println("Your Paramaters cannot understand.");
78
+ System.out.println("Your Paramaters cannot understand.");
79
- break;
79
+ break;
80
- }
80
+ }
81
- }
81
+ }
82
- }
82
+ }
83
+
84
+ }
83
85
 
84
- public static String getInput() {
86
+ public static String getInput() {
85
- BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
87
+ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
86
- double a=0,b=0,c=0,d=0,x1=0,x2=0;
88
+ double a=0,b=0,c=0,d=0,x1=0,x2=0;
87
- String line;
89
+ String line;
88
- int s[]=new int[5];
90
+ int s[]=new int[5];
89
- Scanner sc=new Scanner(System.in);
91
+ Scanner sc=new Scanner(System.in);
90
- for(int i=0;i<s.length; i++) {
92
+ for(int i=0;i<s.length; i++) {
91
- System.out.println("Please Input: a,b,c");
93
+ System.out.println("Please Input: a,b,c");
92
- s[i]=sc.nextInt();
94
+ s[i]=sc.nextInt();
95
+ }
96
+ try {
97
+ for(int i=0; i<s.length; i++) {
98
+ line = reader.readLine();
99
+ System.out.printf("s[%2d]=%d\n",i,s[i]);
100
+ System.out.println("line="+a+", "+b+", "+c);
101
+ }catch(NumberFormatException e) {
102
+ System.out.println("Could you enter the number?");
103
+ System.out.println("Please try again!");
104
+
105
+ }
106
+ }
107
+ if(a==0) {x1=x2=(-c)/b; }
108
+ else {
109
+ //compute the discriminant/
110
+ d=b*b-4*a*c;
111
+ //if D is smaller than Zero, no real solutions.
112
+ if(d<0) {
113
+ System.out.println("There is no solution because the discriminant is negative. D="+d);
114
+ return;
115
+ }else {
116
+ // compute the two solutions.
117
+ x1 =(-b + Math.sqrt(d))/(2*a);
118
+ x2 =(-b - Math.sqrt(d))/(2*a);
119
+ }
93
120
  }
94
- try {
95
- for(int i=0; i<s.length; i++) {
96
- line = reader.readLine();
97
- System.out.printf("s[%2d]=%d\n",i,s[i]);
98
- System.out.println("line="+a+", "+b+", "+c);
99
- }catch(NumberFormatException e) {
100
- System.out.println("Could you enter the number?");
101
- System.out.println("Please try again!");
102
- }
103
- }
104
- if(a==0) {x1=x2=(-c)/b; }
105
- else {
106
- d=b*b-4*a*c;
107
- //if D is smaller than Zero, no real solutions.
108
- if(d<0) {
109
- System.out.println("There is no solution because the discriminant is negative. D="+d);
110
- return;
111
- }else {
112
- x1 =(-b + Math.sqrt(d))/(2*a);
113
- x2 =(-b - Math.sqrt(d))/(2*a);
114
- }
115
- }
116
121
  //disaplay the solutions.
117
122
  System.out.println("x1="+ x1);
118
123
  System.out.println("x2="+ x2);
119
124
  }
120
-
125
+
121
126
  ```
122
127
 
123
128
 

2

エラーメッセージ 抜けていた部分がありました 失礼いたしました

2020/07/07 14:39

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -40,9 +40,8 @@
40
40
 
41
41
  ```java
42
42
  Exception in thread "main" java.lang.Error: Unresolved compilation problem:
43
+ メソッド solveEq(double, double, double) は型 nijikannsuu で未定義です at nijikannsuu.main(Finalreport1.java:23)
43
44
 
44
- at nijikannsuu.main(nijikannsuu.java:7)
45
-
46
45
  ```
47
46
 
48
47
  ###今自分の中でわかっていること

1

大変失礼いたしました。申し訳ございません。こちらでよろしいでしょうか?

2020/07/07 14:32

投稿

Elpa
Elpa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -37,10 +37,14 @@
37
37
  どこにどのプログラムや式を入れ込めばいいのか見当がつきません。
38
38
 
39
39
  ###エラーメッセージ
40
+
41
+ ```java
40
42
  Exception in thread "main" java.lang.Error: Unresolved compilation problem:
41
43
 
42
44
  at nijikannsuu.main(nijikannsuu.java:7)
43
45
 
46
+ ```
47
+
44
48
  ###今自分の中でわかっていること
45
49
  ・キーボードで入力した数字を順番にa,b,cと置きたいが、それの方法が分からない。
46
50
  例)1,-2,-3とキーボードから入力したら、それぞれをa(=1),b(=-2),c(=3)として認識させたい。
@@ -48,72 +52,76 @@
48
52
  ・public static String getInput(){}に問題があることは認識しているのですが、全体的に意味不明になっており、どこから手を付ければいいかわからない状態です。
49
53
 
50
54
  ### 該当のソースコード
55
+ ```java
51
56
  import java.io.BufferedReader;
52
57
  import java.io.IOException;
53
58
  import java.util.Scanner;
54
59
  import java.io.InputStreamReader;
55
60
  public class nijikannsuu {
56
61
 
57
- public static void main(String[] args) {
62
+ public static void main(String[] args) {
58
- String line="";
63
+ String line="";
59
- double a=0,b=0,c=0;
64
+ double a=0,b=0,c=0;
60
- boolean terminate = false;
65
+ boolean terminate = false;
61
- while(true) {
66
+ while(true) {
62
- line=getInput();
67
+ line=getInput();
63
- if(line.equals("finish")) {
68
+ if(line.equals("finish")) {
64
- System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
69
+ System.out.println("Thanks you for using this system.");//finishが入力されたら終了する
65
- return;
70
+ return;
66
- }else
71
+ }else
67
- try {
72
+ try {
68
- String[] abc=line.split(",");
73
+ String[] abc=line.split(",");
69
- a=Double.parseDouble(abc[0]);
74
+ a=Double.parseDouble(abc[0]);
70
- b=Double.parseDouble(abc[1]);
75
+ b=Double.parseDouble(abc[1]);
71
- c=Double.parseDouble(abc[2]);
76
+ c=Double.parseDouble(abc[2]);
72
- solveEq(a,b,c);
77
+ solveEq(a,b,c);
73
- }catch(NumberFormatException e) {
78
+ }catch(NumberFormatException e) {
74
- System.out.println("Your Paramaters cannot understand.");
79
+ System.out.println("Your Paramaters cannot understand.");
75
- break;
80
+ break;
76
- }
81
+ }
77
- }
82
+ }
78
- }
83
+ }
79
84
 
80
- public static String getInput() {
85
+ public static String getInput() {
81
- BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
86
+ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
82
- double a=0,b=0,c=0,d=0,x1=0,x2=0;
87
+ double a=0,b=0,c=0,d=0,x1=0,x2=0;
83
- String line;
88
+ String line;
84
- int s[]=new int[5];
89
+ int s[]=new int[5];
85
- Scanner sc=new Scanner(System.in);
90
+ Scanner sc=new Scanner(System.in);
86
- for(int i=0;i<s.length; i++) {
91
+ for(int i=0;i<s.length; i++) {
87
- System.out.println("Please Input: a,b,c");
92
+ System.out.println("Please Input: a,b,c");
88
- s[i]=sc.nextInt();
93
+ s[i]=sc.nextInt();
89
- }
90
- try {
91
- for(int i=0; i<s.length; i++) {
92
- line = reader.readLine();
93
- System.out.printf("s[%2d]=%d\n",i,s[i]);
94
- System.out.println("line="+a+", "+b+", "+c);
95
- }catch(NumberFormatException e) {
96
- System.out.println("Could you enter the number?");
97
- System.out.println("Please try again!");
98
- }
99
- }
100
- if(a==0) {x1=x2=(-c)/b; }
101
- else {
102
- d=b*b-4*a*c;
103
- //if D is smaller than Zero, no real solutions.
104
- if(d<0) {
105
- System.out.println("There is no solution because the discriminant is negative. D="+d);
106
- return;
107
- }else {
108
- x1 =(-b + Math.sqrt(d))/(2*a);
109
- x2 =(-b - Math.sqrt(d))/(2*a);
110
- }
111
94
  }
95
+ try {
96
+ for(int i=0; i<s.length; i++) {
97
+ line = reader.readLine();
98
+ System.out.printf("s[%2d]=%d\n",i,s[i]);
99
+ System.out.println("line="+a+", "+b+", "+c);
100
+ }catch(NumberFormatException e) {
101
+ System.out.println("Could you enter the number?");
102
+ System.out.println("Please try again!");
103
+ }
104
+ }
105
+ if(a==0) {x1=x2=(-c)/b; }
106
+ else {
107
+ d=b*b-4*a*c;
108
+ //if D is smaller than Zero, no real solutions.
109
+ if(d<0) {
110
+ System.out.println("There is no solution because the discriminant is negative. D="+d);
111
+ return;
112
+ }else {
113
+ x1 =(-b + Math.sqrt(d))/(2*a);
114
+ x2 =(-b - Math.sqrt(d))/(2*a);
115
+ }
116
+ }
112
117
  //disaplay the solutions.
113
118
  System.out.println("x1="+ x1);
114
119
  System.out.println("x2="+ x2);
115
120
  }
121
+
116
-
122
+ ```
123
+
124
+
117
125
  ### 試したこと
118
126
  public static String getInput(){ にある
119
127
  System.out.println("Plese Input : a,b,c");まではできたのですが、