Print number from N to 1 using recursion in java.
import java.util.Scanner;
public class printNtoOne {
public static void print(int x){
if(x==0)
return;
System.out.println(x);
print(x-1);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("enter value of n=");
int n=sc.nextInt();
print(n);
}
}
■》Output->
enter value of n=10
10
9
8
7
6
5
4
3
2
1
Comments
Post a Comment