Write a Java Program to Print 1 To 10 Without Using Loop

Write a Java Program to Print 1 To 10 Without Using Loop thumbnail
52K
By Dhiraj Ray 10 March, 2018

Program Description

Write a java program to print 1 to 10 without using any loop.This can be achieved by using recursion in java.Following is the sample code.

package com.devglan.set2;

public class Print {

    public static void printWithoutLoop(int n) {
        if (n <= 10) {
            System.out.println(n);
            printWithoutLoop(n + 1);
        }
    }

    public static void main(String[] args){
        Print.printWithoutLoop(1);
    }
}

Explanation

Share

If You Appreciate This, You Can Consider:

We are thankful for your never ending support.

About The Author

author-image
A technology savvy professional with an exceptional capacity to analyze, solve problems and multi-task. Technical expertise in highly scalable distributed systems, self-healing systems, and service-oriented architecture. Technical Skills: Java/J2EE, Spring, Hibernate, Reactive Programming, Microservices, Hystrix, Rest APIs, Java 8, Kafka, Kibana, Elasticsearch, etc.