Take a sentence from a user and give output the same sentence with all words in reverse order. Note:Not to use any inbuilt funtion (Today i wnt to interview for Nokia thy asked this Q)
Printable View
Take a sentence from a user and give output the same sentence with all words in reverse order. Note:Not to use any inbuilt funtion (Today i wnt to interview for Nokia thy asked this Q)
Well, what steps would you take to acomplish this task? Frankly, if you're interviewing with Nokia, if you want a shot, this kind of assignment shouldn't be any problem. My recomendations is to take a piece of paper, and try to solve this by hand, see what steps you took, then write them down in pseudocode, like this:
This should give you a clear outline for your program, all that's left is translating plain language into Java.Code:get input from user
get the separate words
etc...
etc...
If this restriction aplies to a commercial project that is developed, then it is indeed stupid, however, as an interview question, it is quite valid. The same line of thinking would be, since Java allocates memory for it's objects automatically, and the garbage collector frees up the memory from objects no longer in use, noone should use C anymore because all that malloc jazz is obsolete.
Even then: it can be useful to break down the problem in terms of existing methods and (re)implement (parts of) those methods yourself if you're not allowed to use those methods. Nowadays I even use 'jamvm' (google it, it is interesting) on very small devices (*); C is history for my job ...
kind regards,
Jos
(*) 32Mbytes is considered small and < 200MHz is considered slow nowadays ;-)