![]() |
Java
1.0
|
Class for checking whether strings are palindromes or anagrams. More...
Static Public Member Functions | |
static boolean | isPalindrome (String s) |
Checks whether a word is a palindrome. More... | |
static String | reverse (String s) |
Reverses a given String. More... | |
static String | revString (String str) |
Recursive version. More... | |
static String | reverseWords (String s) |
Reverses each word in a phrase. More... | |
static String | deAccent (String str) |
Removes diacritical marks, aka accents. More... | |
static String | removeSpacesAndPonctuation (String s) |
Removes spaces and punctuation from a String. More... | |
static boolean | areAnagrams (String s1, String s2) |
Checks whether two strings form an anagram. More... | |
static boolean | isAnagram (String a, String b) |
static boolean | areMutualPalindromes (String s1, String s2) |
Checks whether two strings are mutual palindromes. More... | |
static boolean | isPhrasePalindrome (String s) |
Checks whether a phrase is a palindrome. More... | |
static void | printPalindromeNumbers (int start, int amount) |
Prints the first palindrome numbers beginning at a given point. More... | |
static void | main (String[] args) |
main function for testing. More... | |
Class for checking whether strings are palindromes or anagrams.
Examples:
Examples (mutual palindromes):
Examples (palindrome phrases):
An anagram is a word or phrase formed by reordering the letters of another word or phrase, such as "satin" to "stain".
Examples:
To compile:
To run:
Java can be downloaded from: www.oracle.com
In linux, the version to be used can be set by doing: sudo alternatives –config java
Definition at line 72 of file palindromes.java.
|
static |
Checks whether two strings form an anagram.
An anagram is a type of word play, which is the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once.
For example: "orchestra" can be rearranged into "carthorse".
s1 | first string |
s2 | second string. |
Definition at line 176 of file palindromes.java.
References deAccent(), and removeSpacesAndPonctuation().
Referenced by main().
|
static |
Checks whether two strings are mutual palindromes.
Two words are mutual palindromes when they are the same when one of them is spelt in reverse.
s1 | first string. |
s2 | second string. |
Definition at line 226 of file palindromes.java.
Referenced by main().
|
static |
Removes diacritical marks, aka accents.
It basically converts all accented characters into their deAccented counterparts, followed by their combining diacritics. Then, a regex can be used to strip off the diacritics.
str | a string. |
Definition at line 141 of file palindromes.java.
Referenced by areAnagrams(), isPhrasePalindrome(), and main().
|
static |
Definition at line 188 of file palindromes.java.
Referenced by main().
|
static |
Checks whether a word is a palindrome.
A palindrome is a word or phrase which is the same when spelt in reverse.
s | string to be tested. |
Definition at line 84 of file palindromes.java.
Referenced by main(), and printPalindromeNumbers().
|
static |
Checks whether a phrase is a palindrome.
The only difficulty here is to remove spaces, accents and punctuation from the String.
For example: "A CARA RAJADA DA JARARACA."
s | string to be tested. |
Definition at line 241 of file palindromes.java.
References deAccent(), removeSpacesAndPonctuation(), and reverse().
Referenced by main().
|
static |
main function for testing.
args | string to be tested for being a palindrome word, and a string to be tested for being a palindrome phrase. |
Definition at line 266 of file palindromes.java.
References areAnagrams(), areMutualPalindromes(), deAccent(), isAnagram(), isPalindrome(), isPhrasePalindrome(), printPalindromeNumbers(), reverse(), reverseWords(), and revString().
|
static |
Prints the first palindrome numbers beginning at a given point.
start | beginning point. |
amount | number of palindrome numbers to be printed. |
Definition at line 252 of file palindromes.java.
References isPalindrome(), and baseConverter.itoa().
Referenced by main().
|
static |
Removes spaces and punctuation from a String.
s | string to be processed. |
Definition at line 153 of file palindromes.java.
Referenced by areAnagrams(), and isPhrasePalindrome().
|
static |
Reverses a given String.
s | string to be reverse. |
Definition at line 100 of file palindromes.java.
Referenced by isPhrasePalindrome(), main(), and reverseWords().
|
static |
Reverses each word in a phrase.
s | string to be reversed. |
Definition at line 123 of file palindromes.java.
References reverse().
Referenced by main().
|
static |