-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
31 lines (20 loc) · 539 Bytes
/
Palindrome.java
File metadata and controls
31 lines (20 loc) · 539 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
public class Palindrome {
public boolean isPalindrome(String word) {
boolean flag = true;
char[] wordChar = new char[word.length()];
wordChar = word.toCharArray();
int j = word.length() - 1;
for (int i = 0; i < wordChar.length; i++) {
if (wordChar[i] != wordChar[j]) {
return false;
}
j--;
} // end of for
return true;
}
public static void main(String[] args) {
String word = "madam";
Palindrome p = new Palindrome();
System.out.println(word + " is palindrome?" + p.isPalindrome(word));
}
}