Computer Science, asked by pkman, 1 year ago

how to find the factorial of a number in java​


pkman: nahi
pkman: exams chal rha hai
pkman: so book pdh rha hu

Answers

Answered by BiswajitMJ
1

class FactorialExample2{

static int factorial(int n){

if (n == 0)

return 1;

else

return(n * factorial(n-1));

}

public static void main(String args[]){

int i,fact=1;

int number=4;//It is the number to calculate factorial

fact = factorial(number);

System.out.println("Factorial of "+number+" is: "+fact);

}

}

Output:

Factorial of 4 is: 24

Answered by Anonymous
2
enter a no. and find its factorial .

e.g 5! = 1×2×3×4×5 = 120 .

class Fact

{

public void main( int n )

{

int i = 0, f= 1 ;

for ( i=1; i<=n ; i++ )

{

f= f*i ;

}

System.out.println( " The factorial is " + f ) ;

}

}



it's a blue j input method . I did not use scanner as it's a bit lengthy .

pkman: no problem
Anonymous: lol
pkman: lulwaa
Anonymous: ur kapal
pkman: kapal?
Similar questions