-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrom.java
More file actions
37 lines (30 loc) · 1.11 KB
/
Copy pathPalindrom.java
File metadata and controls
37 lines (30 loc) · 1.11 KB
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
package org.example.quiz;
/**
* @Author : yion
* @Date : 2017. 3. 23.
* @Description : A palindrome is a word that reads the same backward or forward.
* Write a function that checks if a given word is a palindrome. Character case should be ignored.
* For example, isPalindrome("Deleveled") should return true as character case should be ignored,
* resulting in "deleveled", which is a palindrome since it reads the same backward and forward.
*/
public class Palindrom {
public static void main(String[] args) {
System.out.println("Palindrom : " + Palindrom.isPalindrom("Deleveled"));
}
private static boolean isPalindrom(String word) {
if (word == null) {
throw new UnsupportedOperationException("Can't create palindrom!");
}
String result = "";
for (int i = word.length()-1; i >= 0; i--) {
char charword = word.charAt(i);
result += charword;
}
System.out.println("result : " + result);
if (result.equalsIgnoreCase(word)) {
return true;
} else {
return false;
}
}
}