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?:confused:
You can use library functions as well.
Please any one say, if it is possible.
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
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)
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...
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.
Re: Program without loops and recursion
Ok. Thanks for your ideas. I managed to do it with Timers.
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.
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