C Halbe wrote:
Jeff Verdegan wrote:
Your other choice is to tell them to take a hike.
LOL....I was just asking this because this is asked in interviews. If asked, I will have to show the implementation in other language, not Java.
Personally, if this is asked in an interview, I wouldn't just give the "it can't be done in Java" response. I would kindly mention that strings are immutable and asked for more clarification on the question.
I would also ask to see if they are looking for a way to reverse a char array, without using temporary variables. And...
1. if they are looking to reverse an array,without another array, talk about swapping the elements -- using two indexes, one forward, one backwards. (or using one index variable)
2. If they don't even want a temporary char variable, then talk about using bit wise logic to swap the two elements. etc.
Basically, brainstorm. The goal is to show the interviewer your thinking process.
Henry