• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Could you please help me to find whats wrong in the code

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

Could you please help me whats wrong in the code am trying to check a string is palindrome or not?

The second for loop J is not iterating
 
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello muruga dhanapal ,

Why are you using two loops to check for the palindrome nature of the String. I believe a single loop will be enough to accomplish your task as below

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saif Asif wrote:I believe a single loop will be enough to accomplish your task as below...


Saif,

Please don't hand out ready-made solutions. I'm sure you were just trying to help, but we much prefer people to work things out for themselves here.
You also run the risk of misinforming, or providing solutions that are less than optimal - and yours is.

Winston
 
Saif Asif
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Winston Gutkowski ,

or providing solutions that are less than optimal - and yours is.



Please specify where you feel the code is not optimal.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saif Asif wrote:Please specify where you feel the code is not optimal.


All right, since you ask:
1. You don't need to keep a boolean.
2. You don't need to keep another String.
3. You don't need to traverse the entire String.
4. You don't need to call length() on each iteration.
5. Your println() statements belong outside the method (that, admittedly, is arguable; but I stick by it).
6. You never use the variable 'j'.

Winston
 
Saif Asif
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You do not have to doubt my coding conventions . I was merely trying to explain him the problem by his own code sample that he had provided , since it would have been much easier for him to understand his own code rather than to read an entirely different code algorithm. And I also have a firm believe on the fact that there are multiple ways to accomplish a coding task. Not all may be optimal , true , but most are . One should be open to opinions from different programmers.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saif Asif wrote:the fact that there are multiple ways to accomplish a coding task.


Very true.

Not all may be optimal , true , but most are.


Not true. Only one is likely to be optimal, because that's what 'optimal' means - although there may be different ways of writing it.

One should be open to opinions from different programmers.


Opinons are not the issue here. The fact is that you have handed out a solution, when simple advice would have sufficed. It also goes against the ethos of this site, which is to provide help, not code; so please DontBeACodeMill (←click).

Winston
 
Saif Asif
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it :-) I will take care next time :-)
 
I'm so happy! And I wish to make this tiny ad happy too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic