File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
app/src/main/java/hexlet/code/games Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ package hexlet .code .games ;
2+
3+ import hexlet .code .Engine ;
4+
5+ public class GCD {
6+
7+ private static final String RULES = "Find the greatest common divisor of given numbers." ;
8+
9+ public static void gameGCD () {
10+ String [] questions = new String [Engine .ROUNDS ];
11+ String [] correctAnswers = new String [Engine .ROUNDS ];
12+
13+ for (int i = 0 ; i < Engine .ROUNDS ; i ++) {
14+ int firstNumber = (int ) (Math .random () * 100 );
15+ int secondNumber = (int ) (Math .random () * 100 );
16+ questions [i ] = firstNumber + " " + secondNumber ;
17+ int gcd = calculateGCD (firstNumber , secondNumber );
18+ correctAnswers [i ] = Integer .toString (gcd );
19+ }
20+ Engine .game (RULES , questions , correctAnswers );
21+ }
22+
23+ public static int calculateGCD (int a , int b ) {
24+ while (b != 0 ) {
25+ int tmp = b ;
26+ b = a % b ;
27+ a = tmp ;
28+ }
29+ return a ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments