[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Thanks,<br /> <br />Tom
Originally posted by nitin ratra:
hi think it must be tested by the for loops but i want only a program to test for "NITIN" and without buffered reader ....
what i did was ...
for(i=1;1<5;1++){
1term= lastterm
2nd term = second last term
}
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Originally posted by nitin ratra:
Compare the first character with the last character, if they are not the same, it is not a palindrome. If they are the same, compare the second character with the second to the last character. If they are not the same, then it is not a palindrome. If they are the same, repeat the above.
Whenever the characters are not the same, it is not a palindrome and you can stop. If you reach the middle of the string
wat is the code for this
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Originally posted by nitin ratra:
wat is the code for this
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Originally posted by nitin ratra:
step1. mid_index = (total_length - 1)/2 (for odd) or (total_length/2)-1 for even
step2. max_index = total_length - 1 (to pick up letters from end)
step2. loop_index = 0
step3. pick letter at loop_index, pick letter at max_index - loop_index
step4. compare them, if not equal, print "not palindrome" and exit.
step5. loop_index = loop_index + 1
step6. if loop_index > mid_index goto step7 else goto step3
step7. end of loop, and no mismatch found. Hence print "palindrome" and exit.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Originally posted by nitin ratra:
if(str.charat(i) == str.charat(len -1 + i))
}
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
That will printOriginally posted by K. Tsang:
I would have done it something like given string str is the input:
The !ary[i].equals(ary[j]) can be ary[i] != ary[j] for chars.
for a non-palindrome. And it won't compile if you try that parseInt() call. And you are calling an Object method on a char primitive; you must use the == and != operators for chars, not equals().Not Palindrome
Is Palindrome
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Originally posted by Rob Prime:
You can turn that guard into "fwd < last", since if fwd == last then str.charAt(fwd) == str.charAt(last) by definition.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Originally posted by Sagar Rohankar:
O(n/2) - Average
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Originally posted by Campbell Ritchie:
You are correct that you have n/2 repetitions (not called iterations if you use recursion), but the big-O notation calls that O(n) complexity. If you take a word twice as long, your program will run twice as long on average.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Yes. Both instances are called linear complexity.Originally posted by Sagar Rohankar:
So you mean that, the repetitions may be n/2 or n/4 , the complexity must be denoted by O(n) only ! I`m right ?
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Could you hold this puppy for a sec? I need to adjust this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|