Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Please help me on this palindrome program

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Do you call checkData() anywhere ?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
His brain is the size of a cherry pit! About the size of this ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!