Sunday, March 13, 2022

How will you print numbers from 1 to 100 without using loop?

Solution: Use recursive to print numbers without loop.

public class PrintNumbers {

public static void main(String args[]) {

printnumbers(5);

}

public static void printnumbers(int n) {

if(n>0) {

System.out.println(n);

printnumbers(n-1);

}

}

}

No comments:

Post a Comment