• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Please help me on this palindrome program

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator





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!
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you call checkData() anywhere ?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic