File tree 1 file changed +12
-4
lines changed
src/main/java/com/thealgorithms/misc
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,15 @@ private PalindromePrime() {
8
8
}
9
9
10
10
public static boolean prime (int num ) {
11
- if (num < 2 ) return false ; // Handle edge case for numbers < 2
12
- if (num == 2 ) return true ; // 2 is prime
13
- if (num % 2 == 0 ) return false ; // Even numbers > 2 are not prime
11
+ if (num < 2 ) {
12
+ return false ; // Handle edge case for numbers < 2
13
+ }
14
+ if (num == 2 ) {
15
+ return true ; // 2 is prime
16
+ }
17
+ if (num % 2 == 0 ) {
18
+ return false ; // Even numbers > 2 are not prime
19
+ }
14
20
15
21
for (int divisor = 3 ; divisor <= Math .sqrt (num ); divisor += 2 ) {
16
22
if (num % divisor == 0 ) {
@@ -31,7 +37,9 @@ public static int reverse(int n) {
31
37
32
38
public static List <Integer > generatePalindromePrimes (int n ) {
33
39
List <Integer > palindromicPrimes = new ArrayList <>();
34
- if (n <= 0 ) return palindromicPrimes ; // Handle case for 0 or negative input
40
+ if (n <= 0 ) {
41
+ return palindromicPrimes ; // Handle case for 0 or negative input
42
+ }
35
43
36
44
palindromicPrimes .add (2 ); // 2 is the first palindromic prime
37
45
int count = 1 ;
You can’t perform that action at this time.
0 commit comments