What will be the output of the following Java program? [code] class recursion { int fact(int n) {

What will be the output of the following Java program?
Code:
    class recursion 
    {
        int fact(int n) 
        {
            int result;
            if (n == 1)
                return 1;
            result = fact(n - 1) * n;
            return result;
        }
    } 
    class Output 
    {
        public static void main(String args[]) 
        {
            recursion obj = new recursion() ;
            System.out.print(obj.fact(6));
        }
    }
A. 1
B. 30
C. 120
D. 720
 
Answer: d
Explanation: None.
Output:
Code:
$ javac Output.javac
$ java Output
720
This section of our 1000+ Java MCQs focuses on relational operators and boolean logic operators of Java Programming Language.
 

Tìm kiếm

Back
Top