I think i found what is the problem.You are likely to get a stackOverFlowError.Why?

Because of a call of factorial with a negative number.Here is the call

int fnr=factorial(n-r);//n-r=4-2=-2

So go to function factorial and see what happens

static int factorial(int n){
if (n==0)//that's when the recursion is going to stop
return 1;
else
return(n*factorial(n-1));
}

n must reach value 0 in order the recursion to stop.However when n is negative,then the recursion is going to be made by n decremented by one.So in your case,you have -2 then you call factorial with n-1=-2-1=-3 and so on.So n never reaches value zero.As a result the recursion is infinite <-that's bad

As you know factorial for negative ints can not stand logic.If you want to expand to negative(non-int) numbers there is the γάμα (gamma) function.

See at this link for more:

http://answers.yahoo.com/question/in...5190020AAZs7E5