aspose file tools*
The moose likes Beginning Java and the fly likes Please help me on this palindrome program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help me on this palindrome program" Watch "Please help me on this palindrome program" New topic
Author

Please help me on this palindrome program

avelin chen
Greenhorn

Joined: Dec 11, 2005
Posts: 27





The output is supposed to be:

Enter a string ===>> Racecar

String: Racecar
Palindrome: true
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> Aardvark

String: Aardvark
Palindrome: false
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> A man, a plan, a canal, Panama

String: A man, a plan, a canal, Panama
Palindrome: false
Almost Palindrome: true

Do you wish to repeat this program [Y/N]? ===>> n

While on the other hand, my output is:
Enter a string ===>> Racecar

String: Racecar
Palindrome: true
Almost Palindrome: true<--SUPPOSED TO BE FALSE

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> Aardvark

String: Aardvark
Palindrome: false
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> A man, a plan, a canal, Panama

String: A man, a plan, a canal, Panama
Palindrome: false
Almost Palindrome: true

Do you wish to repeat this program [Y/N]? ===>> n

I don't know how to change it without altering the other palindromes. Help will be greatly appreciated!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Do you call checkData() anywhere ?


[My Blog]
All roads lead to JavaRanch
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Perhaps isAlmostPal() should call isPal() first to determine if it is a true palindrome. What can you do with this result to return the value you expect?

Also, you don't need all the if...else statements for your output. Instead you can print the output in a single line:


Java API Documentation
The Java Tutorial
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
Originally posted by avelin chen:

Maybe I am not understanding what the criteria are?

You want anything that is a Palindrome to fail at being an almost palindrome, right? Run that check first - if it passes isPal, it should return false for isAlmostPal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me on this palindrome program