What is the output of the following? // A simple example of recursion.class Factorial { // this is a recursive method int fact(int n) { int result; if(n==1) return 1; result = fact(n-1) * n; return result; }} class Recursion { public static void main(String args[]) { Factorial f = new Factorial(); System.out.println("Factorial of 3 is " + f.fact(3)); }}

A) Factorial of 3 is 3
B) Factorial of 3 is 6
C) Factorial of 3 is 9
D) None of the above

Showing Answers 1 - 12 of 12 Answers

Ali

  • Dec 21st, 2005
 

D) None of the above

Exception in thread "main" java.lang.NoSuchMethodError: main

  Was this answer useful?  Yes

RAMESH

  • Feb 24th, 2006
 

B). Factorial of 3 is 6

  Was this answer useful?  Yes

supriya ahire

  • Mar 22nd, 2006
 

Ans is (d)none of the above

 b'coz we r not defining else part of the if statement.

  acrding to me it's a syntax error.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions