質問編集履歴
1
コード編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
タイトル通り現在String qを r = new Random().nextInt(q.length);
|
1
|
+
タイトル通り現在AndroidStudioでString qを r = new Random().nextInt(q.length);
|
2
2
|
|
3
3
|
((TextView) findViewById(R.id.situmon)).setText(q[r]);
|
4
4
|
|
@@ -10,23 +10,43 @@
|
|
10
10
|
|
11
11
|
public class shindan extends AppCompatActivity {
|
12
12
|
|
13
|
-
String[] q = {
|
13
|
+
String[] q = {
|
14
14
|
|
15
|
-
"
|
15
|
+
"質問1",
|
16
16
|
|
17
|
-
|
17
|
+
"質問2",
|
18
18
|
|
19
|
-
|
19
|
+
"質問3",
|
20
20
|
|
21
|
+
"質問4",
|
21
22
|
|
23
|
+
"質問5"
|
24
|
+
|
25
|
+
"質問6",
|
26
|
+
|
27
|
+
"質問7",
|
28
|
+
|
29
|
+
"質問8",
|
30
|
+
|
31
|
+
"質問9",
|
32
|
+
|
33
|
+
"質問10",
|
34
|
+
|
35
|
+
"質問11"
|
36
|
+
|
37
|
+
};
|
38
|
+
|
39
|
+
String[] ta = {//回答
|
40
|
+
|
41
|
+
"1","2","3","4","5","6","7","8","9","10","11"
|
22
42
|
|
23
43
|
};//+
|
24
44
|
|
25
45
|
|
26
46
|
|
27
|
-
String[] ba = {
|
47
|
+
String[] ba = {//回答
|
28
48
|
|
29
|
-
|
49
|
+
"1","2","3","4","5","6","7","8","9","10","11"
|
30
50
|
|
31
51
|
};//-
|
32
52
|
|
@@ -35,6 +55,18 @@
|
|
35
55
|
int r = 0;//乱数の保管
|
36
56
|
|
37
57
|
int count = 10;//問題数
|
58
|
+
|
59
|
+
int score=0;//スコア
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
int n = 11;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
int[] indexes = getShuffledIndexes(n);
|
68
|
+
|
69
|
+
|
38
70
|
|
39
71
|
|
40
72
|
|
@@ -58,25 +90,13 @@
|
|
58
90
|
|
59
91
|
|
60
92
|
|
61
|
-
|
93
|
+
for (int i = 0; i < n - 1; i++) {
|
62
94
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
public void displayTop() {//上のボタンのテキストを変えるメソッド
|
68
|
-
|
69
|
-
if (r == 0) {
|
70
|
-
|
71
|
-
|
95
|
+
System.out.print(indexes[i] + ", ");
|
72
|
-
|
73
|
-
}else if (r==1){
|
74
|
-
|
75
|
-
((TextView) findViewById(R.id.top)).setText(ta[1]);
|
76
96
|
|
77
97
|
}
|
78
98
|
|
79
|
-
|
99
|
+
System.out.println(indexes[n - 1]);
|
80
100
|
|
81
101
|
|
82
102
|
|
@@ -84,61 +104,43 @@
|
|
84
104
|
|
85
105
|
|
86
106
|
|
87
|
-
public
|
107
|
+
public static int[] getShuffledIndexes(int n) {
|
88
108
|
|
89
|
-
if (
|
109
|
+
if (n <= 0) {
|
90
110
|
|
91
|
-
((TextView) findViewById(R.id.bottom)).setText(ba[0]);
|
92
|
-
|
93
|
-
|
111
|
+
return null;
|
94
|
-
|
95
|
-
((TextView) findViewById(R.id.bottom)).setText(ba[1]);
|
96
112
|
|
97
113
|
}
|
98
114
|
|
99
|
-
|
115
|
+
int[] indexes = new int[n];
|
100
116
|
|
117
|
+
for (int i = 0; i < n; i++) {
|
101
118
|
|
102
|
-
|
103
|
-
public void onTop(View view) {//上のボタンのメソッド
|
104
|
-
|
105
|
-
count--;
|
106
|
-
|
107
|
-
i
|
119
|
+
indexes[i] = i;
|
108
|
-
|
109
|
-
((TextView) findViewById(R.id.tc)).setText("のこり" + count + "問...");
|
110
|
-
|
111
|
-
//出題
|
112
|
-
|
113
|
-
r = new Random().nextInt(q.length);
|
114
|
-
|
115
|
-
((TextView) findViewById(R.id.situmon)).setText(q[r]);
|
116
120
|
|
117
121
|
}
|
118
122
|
|
119
123
|
|
120
124
|
|
121
|
-
|
125
|
+
Random rand = new Random();
|
122
126
|
|
123
|
-
public void onBottom (View view){//下のボタンのメソッド
|
124
127
|
|
125
|
-
count--;
|
126
128
|
|
127
|
-
i
|
129
|
+
for (int i = n - 1; i >= 1; i--) {
|
128
130
|
|
129
|
-
|
131
|
+
int j = rand.nextInt(i + 1);
|
130
132
|
|
131
|
-
|
133
|
+
int tmp = indexes[j];
|
132
134
|
|
133
|
-
|
135
|
+
indexes[j] = indexes[i];
|
134
136
|
|
135
|
-
|
137
|
+
indexes[i] = tmp;
|
136
|
-
|
137
|
-
}
|
138
138
|
|
139
139
|
}
|
140
140
|
|
141
141
|
|
142
|
+
|
143
|
+
return indexes;
|
142
144
|
|
143
145
|
}
|
144
146
|
|