# Need help - using algorithm statements

• 07-22-2008, 03:54 PM
javanewbie
Need help - using algorithm statements
Good day everyone.

I saw a Java program, a PalindromeTest program, with the following codes below:

Code:

```Public Class Palindrometest {     Public Static String Testpalindrome(string Palindrome)     {                         If (Ispalindrome(palindrome) == True) {                     Return "\"" + Palindrome + "\" Is A Palindrome";             }             Else {                     Return "\"" + Palindrome + "\" Is Not A Palindrome";             }             }   [COLOR="Blue"] Public Static Boolean Ispalindrome(string Palindrome)     {         Palindrome = Palindrome.tolowercase();         If (Palindrome.length() <= 1)             Return True;         Char Firstchar = Palindrome.charat(0);         Char Lastchar = Palindrome.charat(palindrome.length()-1);         If (Character.isletter(firstchar) && Character.isletter(lastchar)) {             If (Firstchar != Lastchar) {                 Return False;             } Else {                 String Substring = Palindrome.substring(1,palindrome.length()-1);                 Return Ispalindrome(substring);             }         } Else If (!Character.isletter(firstchar)) {             String Substring = Palindrome.substring(1);             Return Ispalindrome(substring);         } Else {             String Substring = Palindrome.substring(0,palindrome.length()-1);             Return Ispalindrome(substring);         }     }[/COLOR]     Public Static Void Main(string[] Args)     {         System.out.println(testpalindrome("i Enjoy Tacos."));         System.out.println(testpalindrome("damn! I, Agassi, Miss Again! Mad!"));         System.out.println(testpalindrome("yo, Banana Boy!"));         System.out.println(testpalindrome("a Dog! A Panic In A Pagoda!")); Food."));     } }```

i'm just curious what would possible the algorithm behind this codes, especially on how the programmer uses the Character.isLetter, Substring, etc.

i just want to be familiarize with the following codes given. sorry for being a newbie here in java. that's why im asking if you could help me find out the algorithm used in the program.

thanks and have a nice day.
• 07-22-2008, 04:11 PM
Norm
A first attempt to understand what a program does would be to read the API doc for each method that you're not familiar with.
Then use a paper and pencil to play computer and "execute" the code line by line to see what happens. That's pretty much how an experienced programmer would do. Look at each line and do what the computer would do for each method. We can probably do most of it in our heads, but as a beginner, writing it down, drawing pointers, etc would help you visualize what the code is doing.
• 07-23-2008, 11:20 AM
Eranga
In advanced level of a programmer they used of dry run on the application. That's the word they do. Before run any application they simply execute the line-by-line of the code by his/her head and see the result. Then run the application to second it. :)