質問編集履歴

2

質問の1部分が解決したため修正

2018/04/30 04:00

投稿

nagomi72
nagomi72

スコア51

test CHANGED
File without changes
test CHANGED
@@ -2,9 +2,19 @@
2
2
 
3
3
  現在、23,36,39,56行目でシンボルが見つからないというエラーが発生しています。(エラー箇所に★をつけています)
4
4
 
5
- スコープの問題と感じているのですが、例えば23行目、数字と判定したのちに配列であるw_expression_fieldに追加するにはどのようにすればいいのでしょうか。
5
+ ~~スコープの問題と感じているのですが、例えば23行目、数字と判定したのちに配列であるw_expression_fieldに追加するにはどのようにすればいいのでしょうか。~~
6
+
7
+ 上記、if文の外で宣言することで解決しました。
8
+
9
+ 56行目のエラーに取り組みたいと思います。
10
+
11
+
12
+
13
+
6
14
 
7
15
  ご教授のほどよろしくお願いいたします。
16
+
17
+
8
18
 
9
19
 
10
20
 
@@ -16,87 +26,89 @@
16
26
 
17
27
  class Test {
18
28
 
19
- public static void main(String[] args){
20
-
21
- ArrayList<String> w_expression_field = new ArrayList<String>();
22
-
23
-
24
-
25
- while(true){
26
-
27
-
28
-
29
- int w_judge_count = 0; //奇数回、偶数回の判定に使う
29
+ int w_judge_count = 0; // 奇数回、偶数回の判定に使う
30
-
31
- boolean w_number_judge = true; //数字かどうかの判定に使う
32
-
33
- boolean w_operand_judge = true; //演算子かどうかの判定に使う
34
30
 
35
31
 
36
32
 
37
- if(w_judge_count % 2 == 0){ //偶数回なら数字か判定
33
+ public static void main(String[] args) {
38
34
 
39
- while(w_number_judge){ //数字が入力されない限りループ
40
-
41
- System.out.println("数字を入力してください");
42
-
43
- BufferedReader w_input_number = new BufferedReader(new InputStreamReader(System.in));
35
+ ArrayList<String> w_expression_field = new ArrayList<String>();
44
-
45
- String w_changed_input_number = w_input_number.readLine();//入力された文字の型をStringに変換
46
36
 
47
37
 
48
38
 
49
- w_number_judge = isJudgeNumber(w_changed_input_number ); //falseが返ってこれば抜けれる
50
-
51
- }
52
-
53
-
54
-
55
- }
56
-
57
- w_expression_field.add(w_changed_input_number);//入力された値を代入
39
+ while (true) {
58
40
 
59
41
 
60
42
 
43
+ int w_judge_count = 0; // 奇数回、偶数回の判定に使う
61
44
 
45
+ boolean w_number_judge = true; // 数字かどうかの判定に使う
62
46
 
63
- if(w_judge_count % 2 !=0){ //奇数回なら演算子か判定 //else ifでいけるか要検討
47
+ boolean w_operand_judge = true; // 演算子かどうかの判定
64
48
 
65
- while(w_operand_judge){
49
+ String w_changed_input_number = " ";
66
50
 
67
- System.out.println("演算子を入力してください");
68
-
69
- BufferedReader w_input_operand = new BufferedReader(new InputStreamReader(System.in));
70
-
71
- String w_changed_input_operand = w_input_operand.readLine();//入力された文字の型をStringに変換
51
+ String w_changed_input_operand = " ";
72
-
73
-
74
52
 
75
53
 
76
54
 
77
- w_operand_judge = isJudgeOperand(w_changed_input_operand ); //falseが返ってこれば抜けれる
55
+ if (w_judge_count % 2 == 0) { // 偶数回なら数字か判定
78
56
 
79
- }
57
+ while (w_number_judge) { // 数字が入力されない限りループ
80
58
 
81
- }
59
+ System.out.println("数字を入力してください");
82
60
 
83
- if(w_changed_input_operand.equals("=")){//★
61
+ BufferedReader w_input_number = new BufferedReader(new InputStreamReader(System.in));
84
62
 
85
- break;
63
+ w_changed_input_number = w_input_number.readLine();// 入力された文字の型をStringに変換
86
64
 
87
- }
88
65
 
89
- w_expression_field.add(w_changed_input_operand);//入力された値を代入 ★
90
66
 
91
-
67
+ w_number_judge = isJudgeNumber(w_changed_input_number); // falseが返ってこれば抜けれる
92
68
 
93
-
69
+ }
94
70
 
95
- }
96
71
 
97
- //System.out.println("ループから抜け出しました");
98
72
 
99
- }
73
+ }
74
+
75
+ w_expression_field.add(w_changed_input_number);// 入力された値を代入
76
+
77
+
78
+
79
+ if (w_judge_count % 2 != 0) { // 奇数回なら演算子か判定 //else ifでいけるか要検討
80
+
81
+ while (w_operand_judge) {
82
+
83
+ System.out.println("演算子を入力してください");
84
+
85
+ BufferedReader w_input_operand = new BufferedReader(new InputStreamReader(System.in));
86
+
87
+ w_changed_input_operand = w_input_operand.readLine();// 入力された文字の型をStringに変換
88
+
89
+
90
+
91
+ w_operand_judge = isJudgeOperand(w_changed_input_operand); // falseが返ってこれば抜けれる
92
+
93
+ }
94
+
95
+ }
96
+
97
+ if (w_changed_input_operand.equals("=")) {
98
+
99
+ break;
100
+
101
+ }
102
+
103
+ w_expression_field.add(w_changed_input_operand);// 入力された値を代入
104
+
105
+
106
+
107
+ }
108
+
109
+ // System.out.println("ループから抜け出しました");
110
+
111
+ }
100
112
 
101
113
 
102
114
 

1

インデントの整形

2018/04/30 04:00

投稿

nagomi72
nagomi72

スコア51

test CHANGED
File without changes
test CHANGED
@@ -12,9 +12,11 @@
12
12
 
13
13
  import java.util.*;
14
14
 
15
- class Test{
16
15
 
16
+
17
+ class Test {
18
+
17
- public static void main(String[] args){
19
+ public static void main(String[] args){
18
20
 
19
21
  ArrayList<String> w_expression_field = new ArrayList<String>();
20
22
 
@@ -78,7 +80,7 @@
78
80
 
79
81
  }
80
82
 
81
- if(w_changed_input_operand.equals("=")){  
83
+ if(w_changed_input_operand.equals("=")){//
82
84
 
83
85
  break;
84
86
 
@@ -96,47 +98,45 @@
96
98
 
97
99
  }
98
100
 
99
- public static boolean isJudgeNumber(String p_number){
100
101
 
101
- try{
102
102
 
103
- Integer.parseInt(p_number);
103
+ public static boolean isJudgeNumber(String p_number) {
104
104
 
105
- return false;
105
+ try {
106
106
 
107
- }catch(NumberFormatException e){
107
+ Integer.parseInt(p_number);
108
108
 
109
- return true;
109
+ return false;
110
110
 
111
- }
111
+ } catch (NumberFormatException e) {
112
112
 
113
+ return true;
114
+
113
- }
115
+ }
116
+
117
+ }
114
118
 
115
119
 
116
120
 
121
+ public static boolean isJudgeOperand(String p_operand) {
122
+
123
+ if (w_judge_count < 3 && p_operand.equals("=")) { // 最初に=を入力されないように ★
124
+
125
+ return true;
126
+
127
+ } else if (p_operand.equals("+") || p_operand.equals("-") || p_operand.equals("*") || p_operand.equals("/")) { // 演算子ならfalseを返し、ループを抜ける
128
+
129
+ return false;
130
+
131
+ } else {
132
+
133
+ return true;
134
+
135
+ }
136
+
137
+ }
117
138
 
118
139
 
119
- public static boolean isJudgeOperand(String p_operand){
120
-
121
- if(w_judge_count < 3 && p_operand.equals("=")){ //最初に=を入力されないように ★
122
-
123
- return true;
124
-
125
- }else if(p_operand.equals("+") || p_operand.equals("-") || p_operand.equals("*") || p_operand.equals("/")){ //演算子ならfalseを返し、ループを抜ける
126
-
127
- return false;
128
-
129
- }else{
130
-
131
- return true;
132
-
133
- }
134
-
135
- }
136
-
137
-
138
-
139
-
140
140
 
141
141
  }```
142
142