Results 1 to 5 of 5
  1. #1
    rajivjoshi's Avatar
    rajivjoshi is offline Member
    Join Date
    May 2010
    Posts
    13
    Rep Power
    0

    Smile need a logic for this

    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)
    Rajiv Joshi

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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:
    Java Code:
    get input from user
    get the separate words
    etc...
    etc...
    This should give you a clear outline for your program, all that's left is translating plain language into Java.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by rajivjoshi View Post
    Note:Not to use any inbuilt funtion (Today i wnt to interview for Nokia thy asked this Q)
    If Nokia puts those restrictions on a possible answer then Nokia is quite stupid: if a builtin method can accomplish the task and it can do it efficiently one is a moron not to use it ...

    kind regards,

    Jos

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by m00nchile View Post
    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 ;-)

Similar Threads

  1. help with a logic error
    By ShinTec in forum Advanced Java
    Replies: 11
    Last Post: 05-02-2010, 10:19 PM
  2. Java + OOP + Logic Gates = HELP!
    By sev51 in forum New To Java
    Replies: 3
    Last Post: 01-26-2009, 08:42 PM
  3. [SOLVED] need help with logic operator
    By auralius in forum New To Java
    Replies: 10
    Last Post: 12-25-2008, 10:01 PM
  4. Cant get the logic right
    By jermaindefoe in forum New To Java
    Replies: 4
    Last Post: 03-11-2008, 12:22 AM
  5. iterate HashMap with logic
    By Heather in forum Web Frameworks
    Replies: 2
    Last Post: 07-03-2007, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •