質問編集履歴

9

2016/04/05 03:33

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  (例外は発生しているか試しました)
6
6
 
7
+ ```Java
8
+
7
9
  package com.mycompany.myappdiceplus;
8
10
 
9
11
  import android.app.*;
@@ -176,6 +178,8 @@
176
178
 
177
179
  }
178
180
 
181
+ ```
182
+
179
183
  直る前の文
180
184
 
181
185
  結果:成功か失敗(右の合計=乱数,乱数…)

8

2016/04/05 03:33

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -28,45 +28,169 @@
28
28
 
29
29
  public class MainActivity extends Activity{
30
30
 
31
- MediaPlayer SE;
32
-
33
- protected void onCreate(Bundle savedInstanceState){
34
-
35
- super.onCreate(savedInstanceState);
36
-
37
- setContentView(R.layout.main);
38
-
39
- Button button=(Button)findViewById(R.id.bn);
40
-
41
- button.setOnClickListener(new OnClickListener(){
42
-
43
- public void onClick(View Vector){
44
-
45
-
46
-
47
- final EditText DC=(EditText)findViewById(R.id.Dc);
48
-
49
- TextView math=(TextView)findViewById(R.id.text);
50
-
51
- math.setText("???");
52
-
53
- final EditText MAX=(EditText)findViewById(R.id.MAX);
54
-
55
- final EditText kai=(EditText)findViewById(R.id.math);
56
-
57
- SE.start();
58
-
59
-
60
-
61
- int max=0;
62
-
63
- int dice = 0;
64
-
65
-
66
-
67
- int kaisu=0;
68
-
69
-
31
+ MediaPlayer SE;
32
+
33
+
34
+
35
+
36
+
37
+ protected void onCreate(Bundle savedInstanceState){
38
+
39
+ super.onCreate(savedInstanceState);
40
+
41
+ setContentView(R.layout.main);
42
+
43
+ Button button=(Button)findViewById(R.id.bn);
44
+
45
+ button.setOnClickListener(new OnClickListener(){
46
+
47
+ public void onClick(View Vector){
48
+
49
+
50
+
51
+ final EditText DC=(EditText)findViewById(R.id.Dc);
52
+
53
+ TextView math=(TextView)findViewById(R.id.text);
54
+
55
+ math.setText("???");
56
+
57
+ final EditText MAX=(EditText)findViewById(R.id.MAX);
58
+
59
+ final EditText kai=(EditText)findViewById(R.id.math);
60
+
61
+ SE.start();
62
+
63
+ int max=0;
64
+
65
+ int dice = 0;
66
+
67
+
68
+
69
+ int kaisu=0;
70
+
71
+
72
+
73
+
74
+
75
+ max=Integer.parseInt(MAX.getText().toString());
76
+
77
+ dice=Integer.parseInt(DC.getText().toString());
78
+
79
+ kaisu=Integer.parseInt(kai.getText().toString());
80
+
81
+ try
82
+
83
+ {
84
+
85
+ Thread.sleep(1500);
86
+
87
+ }
88
+
89
+ catch (InterruptedException e)
90
+
91
+ {
92
+
93
+ e.printStackTrace();
94
+
95
+ System.exit(1);
96
+
97
+ }
98
+
99
+ int[] sum = new int[kaisu];
100
+
101
+ StringBuilder strings=new StringBuilder();
102
+
103
+ int Random = 0;
104
+
105
+
106
+
107
+ int dex=sum.length;
108
+
109
+ dex--;
110
+
111
+ for(int i=0;i<=dex;i++){
112
+
113
+ sum[i]=new Random().nextInt(max);
114
+
115
+ Random+=sum[i];
116
+
117
+ }
118
+
119
+ strings.append(Random <= dice ? "成功(" : "失敗(");
120
+
121
+ strings.append(Random).append("=");
122
+
123
+
124
+
125
+ for(int index:sum){
126
+
127
+ strings.append(index);
128
+
129
+ strings.append(",");
130
+
131
+ }
132
+
133
+ strings.append(")");
134
+
135
+
136
+
137
+ String ans=strings.toString();
138
+
139
+ math.setText(ans);
140
+
141
+ }
142
+
143
+ });
144
+
145
+ }
146
+
147
+
148
+
149
+ @Override
150
+
151
+ protected void onResume()
152
+
153
+ {
154
+
155
+ super.onResume();
156
+
157
+ SE = MediaPlayer.create(this, R.raw.niconico);
158
+
159
+
160
+
161
+ }
162
+
163
+
164
+
165
+ @Override
166
+
167
+ protected void onDestroy()
168
+
169
+ {
170
+
171
+ onStop();
172
+
173
+ super.onDestroy();
174
+
175
+ }
176
+
177
+ }
178
+
179
+ 直る前の文
180
+
181
+ 結果:成功か失敗(右の合計=乱数,乱数…)
182
+
183
+ と表示したいのですが、
184
+
185
+ 結果:成功(0=)
186
+
187
+ どうしてでしょうか。直し方を教えてください。
188
+
189
+ 一部省く…
190
+
191
+
192
+
193
+ try{
70
194
 
71
195
  max=Integer.parseInt(MAX.getText().toString());
72
196
 
@@ -74,132 +198,14 @@
74
198
 
75
199
  kaisu=Integer.parseInt(kai.getText().toString());
76
200
 
77
- try{
78
-
79
201
  Thread.sleep(1500);
80
202
 
81
203
  }
82
204
 
83
- catch (InterruptedException e){
205
+ catch (Exception e){
84
-
85
- e.printStackTrace();
86
-
87
- System.exit(1);
88
206
 
89
207
  }
90
208
 
91
- //元々ここにint kaisu-1;があった
92
-
93
- int[] sum = new int[kaisu];
94
-
95
- StringBuilder strings=new StringBuilder();
96
-
97
- int Random = 0;
98
-
99
-
100
-
101
- int dex=sum.length;
102
-
103
- dex--;
104
-
105
- for(int i=0;i<=dex;i++){
106
-
107
- sum[i]=new Random().nextInt(max);
108
-
109
- Random+=sum[i];
110
-
111
- }
112
-
113
- strings.append(Random <= dice ? "成功(" : "失敗(");
114
-
115
- strings.append(Random).append("=");
116
-
117
-
118
-
119
- for(int index:sum){
120
-
121
- strings.append(index);
122
-
123
- strings.append(",");
124
-
125
- }
126
-
127
- strings.append(")");
128
-
129
-
130
-
131
- String ans=strings.toString();
132
-
133
- math.setText(ans);
134
-
135
- }
136
-
137
- });
138
-
139
- }
140
-
141
-
142
-
143
- @Override
144
-
145
- protected void onResume()
146
-
147
- {
148
-
149
- super.onResume();
150
-
151
- SE = MediaPlayer.create(this, R.raw.niconico);
152
-
153
-
154
-
155
- }
156
-
157
-
158
-
159
- @Override
160
-
161
- protected void onDestroy()
162
-
163
- {
164
-
165
- onStop();
166
-
167
- super.onDestroy();
168
-
169
- }
170
-
171
- }
172
-
173
- 直る前の文
174
-
175
- 結果:成功か失敗(右の合計=乱数,乱数…)
176
-
177
- と表示したいのですが、
178
-
179
- 結果:成功(0=)
180
-
181
- どうしてでしょうか。直し方を教えてください。
182
-
183
- 一部省く…
184
-
185
-
186
-
187
- try{
188
-
189
- max=Integer.parseInt(MAX.getText().toString());
190
-
191
- dice=Integer.parseInt(DC.getText().toString());
192
-
193
- kaisu=Integer.parseInt(kai.getText().toString());
194
-
195
- Thread.sleep(1500);
196
-
197
- }
198
-
199
- catch (Exception e){
200
-
201
- }
202
-
203
209
  int kaisu-1;
204
210
 
205
211
 

7

2016/04/05 03:23

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -110,49 +110,23 @@
110
110
 
111
111
  }
112
112
 
113
-
114
-
115
- if (Random <= dice){
113
+ strings.append(Random <= dice ? "成功(" : "失敗(");
116
-
114
+
117
- strings.append("結果:");
115
+ strings.append(Random).append("=");
118
-
116
+
117
+
118
+
119
- strings.append("成功(");
119
+ for(int index:sum){
120
-
120
+
121
- strings.append(Random);
121
+ strings.append(index);
122
-
123
- strings.append("=");
122
+
124
-
125
- for(int i:sum){
126
-
127
- strings.append(i);
128
-
129
- strings.append(",");
123
+ strings.append(",");
130
-
131
- }
132
-
133
- }else{
134
-
135
- strings.append("結果");
136
-
137
- strings.append("失敗(");
138
-
139
- strings.append(Random);
140
-
141
- strings.append("=");
142
-
143
- for (int i:sum){
144
-
145
- strings.append(i);
146
-
147
- strings.append(",");
148
-
149
- }
150
124
 
151
125
  }
152
126
 
153
127
  strings.append(")");
154
128
 
155
-
129
+
156
130
 
157
131
  String ans=strings.toString();
158
132
 

6

2016/04/05 03:20

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
@@ -1 +1 @@
1
- Androidアプリの無駄な動作を教えてほしい
1
+ Android用サイコロアプリの無駄な動作を教えてほしい
test CHANGED
File without changes

5

2016/04/05 03:10

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
@@ -1 +1 @@
1
- Androidアプリがうまくかな
1
+ Androidアプリの無駄な作を教えてほし
test CHANGED
@@ -1,82 +1,216 @@
1
- http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q14157795609
2
-
3
- にも投稿しましたがteratailにも投稿させて頂きます。
4
-
5
1
  本文
6
2
 
3
+ うまく動くようになったので改善できるところを教えてください。
4
+
5
+ (例外は発生しているか試しました)
6
+
7
+ package com.mycompany.myappdiceplus;
8
+
9
+ import android.app.*;
10
+
11
+ import android.os.*;
12
+
13
+ import android.widget.*;
14
+
15
+ import android.view.View.*;
16
+
17
+ import android.view.*;
18
+
19
+ import java.util.*;
20
+
21
+ import android.media.*;
22
+
23
+ import android.content.*;
24
+
25
+ import android.widget.AutoCompleteTextView.*;
26
+
27
+
28
+
29
+ public class MainActivity extends Activity{
30
+
31
+ MediaPlayer SE;
32
+
33
+ protected void onCreate(Bundle savedInstanceState){
34
+
35
+ super.onCreate(savedInstanceState);
36
+
37
+ setContentView(R.layout.main);
38
+
39
+ Button button=(Button)findViewById(R.id.bn);
40
+
41
+ button.setOnClickListener(new OnClickListener(){
42
+
43
+ public void onClick(View Vector){
44
+
45
+
46
+
47
+ final EditText DC=(EditText)findViewById(R.id.Dc);
48
+
49
+ TextView math=(TextView)findViewById(R.id.text);
50
+
51
+ math.setText("???");
52
+
53
+ final EditText MAX=(EditText)findViewById(R.id.MAX);
54
+
55
+ final EditText kai=(EditText)findViewById(R.id.math);
56
+
57
+ SE.start();
58
+
59
+
60
+
61
+ int max=0;
62
+
63
+ int dice = 0;
64
+
65
+
66
+
67
+ int kaisu=0;
68
+
69
+
70
+
71
+ max=Integer.parseInt(MAX.getText().toString());
72
+
73
+ dice=Integer.parseInt(DC.getText().toString());
74
+
75
+ kaisu=Integer.parseInt(kai.getText().toString());
76
+
77
+ try{
78
+
79
+ Thread.sleep(1500);
80
+
81
+ }
82
+
83
+ catch (InterruptedException e){
84
+
85
+ e.printStackTrace();
86
+
87
+ System.exit(1);
88
+
89
+ }
90
+
91
+ //元々ここにint kaisu-1;があった
92
+
93
+ int[] sum = new int[kaisu];
94
+
95
+ StringBuilder strings=new StringBuilder();
96
+
97
+ int Random = 0;
98
+
99
+
100
+
101
+ int dex=sum.length;
102
+
103
+ dex--;
104
+
105
+ for(int i=0;i<=dex;i++){
106
+
107
+ sum[i]=new Random().nextInt(max);
108
+
109
+ Random+=sum[i];
110
+
111
+ }
112
+
113
+
114
+
115
+ if (Random <= dice){
116
+
117
+ strings.append("結果:");
118
+
119
+ strings.append("成功(");
120
+
121
+ strings.append(Random);
122
+
123
+ strings.append("=");
124
+
125
+ for(int i:sum){
126
+
127
+ strings.append(i);
128
+
129
+ strings.append(",");
130
+
131
+ }
132
+
133
+ }else{
134
+
135
+ strings.append("結果");
136
+
137
+ strings.append("失敗(");
138
+
139
+ strings.append(Random);
140
+
141
+ strings.append("=");
142
+
143
+ for (int i:sum){
144
+
145
+ strings.append(i);
146
+
147
+ strings.append(",");
148
+
149
+ }
150
+
151
+ }
152
+
153
+ strings.append(")");
154
+
155
+
156
+
157
+ String ans=strings.toString();
158
+
159
+ math.setText(ans);
160
+
161
+ }
162
+
163
+ });
164
+
165
+ }
166
+
167
+
168
+
169
+ @Override
170
+
171
+ protected void onResume()
172
+
173
+ {
174
+
175
+ super.onResume();
176
+
177
+ SE = MediaPlayer.create(this, R.raw.niconico);
178
+
179
+
180
+
181
+ }
182
+
183
+
184
+
185
+ @Override
186
+
187
+ protected void onDestroy()
188
+
189
+ {
190
+
191
+ onStop();
192
+
193
+ super.onDestroy();
194
+
195
+ }
196
+
197
+ }
198
+
199
+ 直る前の文
200
+
7
201
  結果:成功か失敗(右の合計=乱数,乱数…)
8
202
 
9
- とのように出しますが、何故か必ず成功になり、次のようになります。
203
+ 表示したいすが、
10
204
 
11
205
  結果:成功(0=)
12
206
 
13
207
  どうしてでしょうか。直し方を教えてください。
14
208
 
15
- (例外は発生しているか試しました)
16
-
17
- package com.mycompany.myappdiceplus;
18
-
19
- import android.app.*;
20
-
21
- import android.os.*;
22
-
23
- import android.widget.*;
24
-
25
- import android.view.View.*;
26
-
27
- import android.view.*;
28
-
29
- import java.util.*;
30
-
31
- import android.media.*;
32
-
33
- import android.content.*;
34
-
35
- import android.widget.AutoCompleteTextView.*;
36
-
37
-
38
-
39
- public class MainActivity extends Activity{
40
-
41
- MediaPlayer SE;
209
+ 一部省く…
42
-
43
- protected void onCreate(Bundle savedInstanceState){
210
+
44
-
45
- super.onCreate(savedInstanceState);
211
+
46
-
47
- setContentView(R.layout.main);
212
+
48
-
49
- Button button=(Button)findViewById(R.id.bn);
50
-
51
- button.setOnClickListener(new OnClickListener(){
52
-
53
- public void onClick(View Vector){
54
-
55
-
56
-
57
- final EditText DC=(EditText)findViewById(R.id.Dc);
58
-
59
- TextView math=(TextView)findViewById(R.id.text);
60
-
61
- math.setText("???");
62
-
63
- final EditText MAX=(EditText)findViewById(R.id.MAX);
64
-
65
- final EditText kai=(EditText)findViewById(R.id.math);
66
-
67
- SE.start();
213
+ try{
68
-
69
- int max=0;
70
-
71
- int dice = 0;
72
-
73
-
74
-
75
- int kaisu=0;
76
-
77
-
78
-
79
-
80
214
 
81
215
  max=Integer.parseInt(MAX.getText().toString());
82
216
 
@@ -84,124 +218,14 @@
84
218
 
85
219
  kaisu=Integer.parseInt(kai.getText().toString());
86
220
 
87
- try{
88
-
89
221
  Thread.sleep(1500);
90
222
 
91
223
  }
92
224
 
93
- catch (InterruptedException e){
225
+ catch (Exception e){
94
-
95
- e.printStackTrace();
226
+
96
-
97
- System.exit(1);
98
-
99
- }
227
+ }
100
-
101
-
102
-
103
- int[] sum = new int[kaisu];
228
+
104
-
105
- StringBuilder strings=new StringBuilder();
106
-
107
- int Random = 0;
229
+ int kaisu-1;
108
-
109
-
110
-
111
- int dex=sum.length;
230
+
112
-
113
- dex--;
114
-
115
- for(int i=0;i<=dex;i++){
116
-
117
- sum[i]=new Random().nextInt(max);
118
-
119
- Random+=sum[i];
120
-
121
- }
231
+
122
-
123
-
124
-
125
- if (Random <= dice){
126
-
127
- strings.append("結果:");
128
-
129
- strings.append("成功(");
130
-
131
- strings.append(Random);
132
-
133
- strings.append("=");
134
-
135
- for(int i:sum){
136
-
137
- strings.append(i);
138
-
139
- strings.append(",");
140
-
141
- }
142
-
143
- }else{
144
-
145
- strings.append("結果");
146
-
147
- strings.append("失敗(");
148
-
149
- strings.append(Random);
150
-
151
- strings.append("=");
152
-
153
- for (int i:sum){
154
-
155
- strings.append(i);
156
-
157
- strings.append(",");
158
-
159
- }
160
-
161
- }
162
-
163
- strings.append(")");
164
-
165
-
166
-
167
- String ans=strings.toString();
168
-
169
- math.setText(ans);
170
-
171
- }
172
-
173
- });
174
-
175
- }
176
-
177
-
178
-
179
- @Override
180
-
181
- protected void onResume()
182
-
183
- {
184
-
185
- super.onResume();
186
-
187
- SE = MediaPlayer.create(this, R.raw.niconico);
188
-
189
-
190
-
191
- }
192
-
193
-
194
-
195
- @Override
196
-
197
- protected void onDestroy()
198
-
199
- {
200
-
201
- onStop();
202
-
203
- super.onDestroy();
204
-
205
- }
206
-
207
- }

4

2016/04/05 03:07

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -76,27 +76,29 @@
76
76
 
77
77
 
78
78
 
79
+
80
+
81
+ max=Integer.parseInt(MAX.getText().toString());
82
+
83
+ dice=Integer.parseInt(DC.getText().toString());
84
+
85
+ kaisu=Integer.parseInt(kai.getText().toString());
86
+
79
87
  try{
80
88
 
81
- max=Integer.parseInt(MAX.getText().toString());
82
-
83
- dice=Integer.parseInt(DC.getText().toString());
84
-
85
- kaisu=Integer.parseInt(kai.getText().toString());
86
-
87
89
  Thread.sleep(1500);
88
90
 
89
91
  }
90
92
 
91
- catch(Exception e){
93
+ catch (InterruptedException e){
94
+
92
-
95
+ e.printStackTrace();
96
+
93
-
97
+ System.exit(1);
94
-
98
+
95
- }
99
+ }
96
-
97
-
98
-
99
- kaisu-=1;
100
+
101
+
100
102
 
101
103
  int[] sum = new int[kaisu];
102
104
 

3

2016/04/05 02:57

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -66,13 +66,13 @@
66
66
 
67
67
  SE.start();
68
68
 
69
- int max=100;
69
+ int max=0;
70
-
70
+
71
- int dice = 25;
71
+ int dice = 0;
72
-
73
-
74
-
72
+
73
+
74
+
75
- int kaisu=1;
75
+ int kaisu=0;
76
76
 
77
77
 
78
78
 

2

2016/04/05 02:48

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  どうしてでしょうか。直し方を教えてください。
14
14
 
15
+ (例外は発生しているか試しました)
16
+
15
17
  package com.mycompany.myappdiceplus;
16
18
 
17
19
  import android.app.*;

1

2016/04/05 02:38

投稿

sun-solar-arrow
sun-solar-arrow

スコア113

test CHANGED
File without changes
test CHANGED
@@ -104,7 +104,9 @@
104
104
 
105
105
 
106
106
 
107
- int dex=sum.length-1;
107
+ int dex=sum.length;
108
+
109
+ dex--;
108
110
 
109
111
  for(int i=0;i<=dex;i++){
110
112