mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 01:35:16 +08:00
Merge pull request #1 from earngpi/earngpi-version
create Palindrome.java
This commit is contained in:
16
Misc/Palindrome.java
Normal file
16
Misc/Palindrome.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class Palindrome {
|
||||||
|
|
||||||
|
public String reverseString(String x){ //*helper method
|
||||||
|
String output = "";
|
||||||
|
for(int i=x.length()-1; i>=0; i--){
|
||||||
|
output += x.charAt(i); //addition of chars create String
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Boolean isPalindrome(String x){ //*palindrome method, returns true if palindrome
|
||||||
|
return (x.equalsIgnoreCase(reverseString(x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user