@@ -24,34 +24,32 @@ public static String[][] generateData() {
2424 int start = Utils .getRandomInt (0 , MAX_START );
2525 int step = Utils .getRandomInt (1 , MAX_STEP + 1 );
2626
27- String [] progression = generateProgression (start , step , progressionLength );
27+ int [] progression = generateProgression (start , step , progressionLength );
2828
29- questionsAndAnswers [i ][0 ] = progression [0 ];
30- questionsAndAnswers [i ][1 ] = progression [1 ];
29+ String [] stringProgression = new String [progression .length ];
30+ for (int j = 0 ; j < progression .length ; j ++) {
31+ stringProgression [j ] = Integer .toString (progression [j ]);
32+ }
33+
34+ int missingIndex = Utils .getRandomInt (0 , progressionLength - 1 );
35+ String missingNumber = stringProgression [missingIndex ];
36+ stringProgression [missingIndex ] = ".." ;
37+
38+ String question = String .join (" " , stringProgression );
39+
40+ questionsAndAnswers [i ][0 ] = question ;
41+ questionsAndAnswers [i ][1 ] = missingNumber ;
3142 }
3243 return questionsAndAnswers ;
3344 }
3445
35- public static String [] generateProgression (int start , int step , int length ) {
46+ public static int [] generateProgression (int start , int step , int length ) {
3647 int [] progression = new int [length ];
3748
3849 for (int i = 0 ; i < length ; i ++) {
3950 progression [i ] = start + i * step ;
4051 }
4152
42- int missingIndex = Utils .getRandomInt (0 , length - 1 );
43- int missingNumber = progression [missingIndex ];
44-
45- String [] formattedProgression = new String [length ];
46-
47- for (int i = 0 ; i < length ; i ++) {
48- if (i == missingIndex ) {
49- formattedProgression [i ] = ".." ;
50- } else {
51- formattedProgression [i ] = Integer .toString (progression [i ]);
52- }
53- }
54- String question = String .join (" " , formattedProgression );
55- return new String []{question , Integer .toString (missingNumber )};
53+ return progression ;
5654 }
5755}
0 commit comments