Results 1 to 3 of 3
- 07-22-2008, 03:54 PM #1
Member
- Join Date
- Jun 2008
- Location
- Australia
- Posts
- 43
- Rep Power
- 0
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); } }[/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 #2
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.
- 07-23-2008, 11:20 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
avoiding if statements
By valoyivd in forum New To JavaReplies: 1Last Post: 04-02-2008, 09:08 AM -
Help with actionPerformed Statements
By wco5002 in forum New To JavaReplies: 8Last Post: 03-26-2008, 04:02 AM -
Paper,Scissor,Rock If then Statements
By Alberto in forum New To JavaReplies: 2Last Post: 02-11-2008, 11:18 PM -
How to Execute SQL statements in Spring Framework
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:59 PM -
Help with if else statements
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 07:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks