Skip to content

Commit 72be368

Browse files
committed
edit Even.java for SonarQube
1 parent cf9eda2 commit 72be368

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/src/main/java/hexlet/code/Even.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package hexlet.code;
22
import java.util.Scanner;
3+
import java.security.SecureRandom;
34

45
public class Even {
56
public static boolean generateNumber(String userName) {
@@ -8,11 +9,12 @@ public static boolean generateNumber(String userName) {
89
int correctAnswerCount = 0;
910
final int rounds = 3;
1011
while (correctAnswerCount <= rounds) {
11-
int random = (int) (Math.random() * 100);
12-
System.out.println("Question: " + random);
12+
SecureRandom random = new SecureRandom();
13+
int number = random.nextInt(100) + 1;
14+
System.out.println("Question: " + number);
1315
String answer = scanner.next();
1416
System.out.println("Your answer: " + answer);
15-
boolean isCorrect = random % 2 == 0 ? answer.equals("yes") : answer.equals("no");
17+
boolean isCorrect = number % 2 == 0 ? answer.equals("yes") : answer.equals("no");
1618
if (isCorrect) {
1719
correctAnswerCount++;
1820
System.out.println("Correct!");
@@ -21,7 +23,7 @@ public static boolean generateNumber(String userName) {
2123
return true;
2224
}
2325
} else {
24-
String correctAnswer = random % 2 == 0 ? "'yes'" : "'no'";
26+
String correctAnswer = number % 2 == 0 ? "'yes'" : "'no'";
2527
System.out.println("'" + answer + "' is wrong answer ;(. Correct answer was " + correctAnswer
2628
+ ".\nLet's try again, " + userName + "!");
2729
return false;

0 commit comments

Comments
 (0)