Program to print name 100 times using recursion in Java |EasyCoding45

Write a Program to print name 100 times using recursion in Java


In this Tutorial we are going to learn how we can Write a Program to print name 100 times using recursion in Java.


Recursion :-

                    Recursion is defined as if a function calls itself then it is known as "Recursion".


Program :-(Program to print name 100 times using recursion in Java)


import java.util.*;

class recursion

{

String name;

int cnt;

void printname(String nm,int count)

{

name=nm;

cnt=count;

if(cnt>0)

{

System.out.println("Name is :"+name);

}

else

{

System.exit(0);

}

printname(name,cnt-1);

}

}

class run

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter Name :");

String name=sc.next();

recursion r=new recursion();

r.printname(name,100);

}

}


Output :-



Please Comment if you have any doubt 👇

Comments