Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Program without loops and recursion

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Program without loops and recursion

    Hi,
    I was asked to write a Java pgm in a contest. But i couldn't do it. I don't know the answer yet. So, I thought i'd ask here. And the problem is , can we write a java program to print numbers 1 to 1000 without using any loops and recursion?

    You can use library functions as well.

    Please any one say, if it is possible.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Program without loops and recursion

    Well you could hard code the numbers in xD

    There are many solutions which claim to satisfy this, but it depends on what you take to be recursion and loops, does this include compile time loops and recursion?

    Chris

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Program without loops and recursion

    Hard coding is the easiest method.

    A swing timer/event driven model might count depending on who you ask (there are parts that could be considered recursive or loops)

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program without loops and recursion

    The program should not syntactically contain any loops or recursion. that's it.
    Btw, i don't want to hard code.
    Pls give me any 1 soln...

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Program without loops and recursion

    We won't just give you a solution. If you want an event-driven program, I'd suggest reading on Swing Timers and Action Listeners.

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program without loops and recursion

    Ok. Thanks for your ideas. I managed to do it with Timers.

  7. #7
    Member
    Join Date
    Feb 2010
    Location
    Auburn, AL
    Posts
    31
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: Program without loops and recursion

    Sort of a silly contest problem... hard coding is the obvious method, and you could write a trivial ~20 line program to generate the >1000 line program in literally no time.
    Let me know what you think of my website:
    http://www.auburn.edu/~carpept
    Comments or suggestions are appreciated!

  8. #8
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Program without loops and recursion

    True, you can also use divide & conquer approach

    It's a well known programming challenge, it's more to stimulate the mind and get you thinking about ways of doing things.

    Chris

Similar Threads

  1. Recursion help
    By rhoruns in forum Algorithms & Recursion
    Replies: 4
    Last Post: January 8th, 2010, 11:50 PM
  2. Simple recursion logic
    By chronoz13 in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 24th, 2009, 10:53 PM
  3. Program with for loops help
    By ixjaybeexi in forum Loops & Control Statements
    Replies: 23
    Last Post: October 8th, 2009, 10:05 AM
  4. Problems with recursion
    By KingLane in forum Algorithms & Recursion
    Replies: 4
    Last Post: September 20th, 2009, 11:02 PM
  5. [SOLVED] Fixing of bug in number guessing game
    By big_c in forum Loops & Control Statements
    Replies: 6
    Last Post: April 16th, 2009, 02:15 AM