Skip to content

Commit d70980d

Browse files
committed
refactor: adding a check to isPrime()
1 parent d07532b commit d70980d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

app/src/main/java/hexlet/code/games/Prime.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public class Prime {
77
private static final int MIN = 2;
88
private static final int MAX = 1000;
9+
910
public static void startGame() {
1011

1112
String[][] roundsData = new String[Engine.ROUNDS][2];
@@ -21,6 +22,9 @@ public static void startGame() {
2122
}
2223

2324
public static boolean isPrime(int num) {
25+
if (num <= 0) {
26+
return false;
27+
}
2428
for (int i = 2; i <= Math.sqrt(num); i++) {
2529
if (num % i == 0) {
2630
return false;

0 commit comments

Comments
 (0)