dsa/Recursion/PrintMtoN.java

27 lines
703 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.util.Scanner;
class PrintMtoN {
static void func(int i, int n){
// Base Condition.
if(i<n) return;
System.out.println(i);
// Function call to print i till i decrements to 1.
func(i-1,n);
}
public static void main(String[] args) {
// Here, lets take the value of n to be 4.
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of m (Ending Variable): ");
int m = sc.nextInt();
System.out.println("Enter the value of n (Starting Variable): ");
int n = sc.nextInt();
//int n = 8;
func(m,n);
sc.close();
}
}