Java program to print numbers without using loop

Java program to print numbers without using loop

In this post we will see Java program to print numbers from 1 to N without using loop. This is one of the frequently asked Java coding interview questions for experience of 0-2 years.

Solution approach#1:

Solution approach#2:

In the first approach we have used recursion to simulate looping and in second approach we have used Arrays.toString() method which actually uses loop internally.

The program might look simple but it is important to remember the logic so that it will become easy to write it during an interview.

Hope you find the post useful.

Also read my posts on Frequently asked Java interview questions with answers

The following two tabs change content below.
Working as a Java developer since 2010. Passionate about programming in Java. I am a part time blogger.
One comment

Add Comment

Required fields are marked *. Your email address will not be published.