Results 1 to 3 of 3
  1. #1
    javanewbie is offline Member
    Join Date
    Jun 2008
    Rep Power

    Default Need help - using algorithm statements

    Good day everyone.

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

    Java 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);
        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!"));

    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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    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.
    Last edited by Norm; 07-22-2008 at 04:13 PM.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    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. :)

Similar Threads

  1. avoiding if statements
    By valoyivd in forum New To Java
    Replies: 1
    Last Post: 04-02-2008, 09:08 AM
  2. Help with actionPerformed Statements
    By wco5002 in forum New To Java
    Replies: 8
    Last Post: 03-26-2008, 04:02 AM
  3. Paper,Scissor,Rock If then Statements
    By Alberto in forum New To Java
    Replies: 2
    Last Post: 02-11-2008, 11:18 PM
  4. Replies: 0
    Last Post: 09-28-2007, 12:59 PM
  5. Help with if else statements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 07:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts