There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
shuba gopal wrote:Hi I am trying to check if the elements in a given array are Palindrome. The flow does not enter the second for loop( for(int j=b-1;j<=mid2;j--). Eclipse does not show any errors. Any ideas? Thanks
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ninad Kulkarni wrote:I written below code for palindrome in that I didn't used nested loop...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ninad Kulkarni wrote:
I written below code for palindrome in that I didn't used nested loop. You can refer below code.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Winston Gutkowski wrote:...most of the forums that I belong to frown on full-code solutions. Far better to steer OP in the right direction and let the lightbulb come on by itself.
Winston
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:...In fact, it is even one of the points on our HowToAnswerQuestionsOnJavaRanch FAQ.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
shuba gopal wrote:For the second loop, for(int j=b-1;j==mid2;j--) - b-1 = 5 and j=3. SOP just inside this loop is not printed. I just wanted to confirm if my usage is correct. Thanks Shuba
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:Please don't provide full solutions like this. We want people to learn to code for themselves. Handing them a fully implemented answer doesn't really help them learn, just like handing someone a fish doesn't help them eat tomorrow.
SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
shuba gopal wrote:For the second loop, for(int j=b-1;j==mid2;j--) - b-1 = 5 and j=3. SOP just inside this loop is not printed. I just wanted to confirm if my usage is correct. Thanks Shuba
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
shuba gopal wrote:Winston, I finally figured out that the same logic applies when the number of elements are odd or even. I cant believe I missed this. Writing it out does clear things up. Many thanks.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:You should also reformat that code. { and } on lines by themselves.
Joanne
Campbell Ritchie wrote:I’m not letting you have the last word...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
You realise that you only need to traverse half an array to find out whether it is palindromic? If arr[0] == arr[arr.length - i], then arr[arr.length - i] == arr[0].shuba gopal wrote: . . . Winston, I finally figured out that the same logic applies when the number of elements are odd or even. . . .
Rob Spoor wrote:I switched from 80 to 120 character maximums recently, because 80 made me jump through hoops at times to get a proper looking layout while still keeping under 80. 120 looked well enough on my screen. I agree on (most of) section 3 being rubbish.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:I did say Joanne was right. She and I have been winding each other up for ages...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Campbell Ritchie wrote:I’m not letting you have the last word...
Actually, I'm with Joanne on that one. I generally stick me opening braces at the end of the line unless space dictates otherwise
Joanne
Joanne Neal wrote:It means I (currently) have the last word on the subject
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Joanne
I won’t.Joanne Neal wrote:Don't give up the day job
Winston Gutkowski wrote:
Rob Spoor wrote:I switched from 80 to 120 character maximums recently, because 80 made me jump through hoops at times to get a proper looking layout while still keeping under 80. 120 looked well enough on my screen. I agree on (most of) section 3 being rubbish.
Ah, you're fond of reallyReallyDescriptiveAndDetailed() method/class/field names are you? Or do you like Builders?
Actually, me too (both); but I try to keep it to a dull roar .
Winston
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
More a design principle than style, but I agree. I read somewhere (forget where) that a method should be less than half a page, and a method which goes over a whole page really ought to be refactored.Winston Gutkowski wrote: . . .
BTW, the one major piece of advice that I think should be in every guideline . . .
Keep your methods short. . . .
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|