Print N to 1 Using Recursion

PHOTO EMBED

Sun Feb 06 2022 20:34:51 GMT+0000 (Coordinated Universal Time)

Saved by @Uttam #java #gfg #geeksforgeeks #lecture #recursion #printn to 1 using recursion

import java.io.*;
import java.util.*;

class GFG {

	
	static void printToN(int n)
	{
		if(n == 0)
			return;
		
		System.out.print(n+" ");
		
		printToN(n - 1);

	}
    public static void main(String [] args) 
    {
    	int n = 4;

    	printToN(n);
        
    }

}
content_copyCOPY

OUTPUT : ----------- 4 3 2 1