Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 1, 2018 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/f5f66b1643b165610559e4bc2ca71bcb to your computer and use it in GitHub Desktop.
Save thmain/f5f66b1643b165610559e4bc2ca71bcb to your computer and use it in GitHub Desktop.
public class PrintNumbersWithOutLoop {
static void printNumbers(int number){
if(number<=0)
return;
//else make a recursive call
printNumbers(number-1);
//print number in tail recursive
System.out.print(number + " ");
}
public static void main(String[] args) {
int n = 20;
printNumbers(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment