-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPalindomeEx.java
More file actions
38 lines (31 loc) · 970 Bytes
/
PalindomeEx.java
File metadata and controls
38 lines (31 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.coderbd;
import java.math.BigInteger;
public class PalindomeEx {
public static void main(String[] args) {
System.out.println(PalindomeEx.isPalindome("moam"));
System.out.println("Is Prime: " + isPrime(10));
checkPrimeNumbers(1, 100);
}
public static boolean isPalindome(String s) {
boolean palindome = false;
if (s.equalsIgnoreCase(new StringBuilder(s).reverse().toString())) {
palindome = true;
}
return palindome;
}
public static void checkPrimeNumbers(int n1, int n2) {
while (n1 <= n2) {
if (isPrime(n1)) {
System.out.println(n1 + " is prime? " + isPrime(n1));
}
n1++;
}
}
public static boolean isPrime(int num) {
boolean prime = false;
if (new BigInteger(String.valueOf(num)).isProbablePrime(num)) {
prime = true;
}
return prime;
}
}