Program:
import java.util.Scanner;
public class FactorialProgram {
public static int factorialValue(int n){
int fact = 1;
for ( int i= 1 ; i <= n ; i++ ){
fact = fact*i;
//condition is failed ,when i value is 4.Otherwise loop reapeted
}
return fact;
}// method
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter an only +ve Integer Number : ");
int n = in.nextInt();
int result=FactorialProgram.factorialValue(n);
System.out.println("Factorial of "+n+" is = "+result);
}//main
}// class
output:
Enter an only +ve Integer Number :
4
Factorial of 4 is = 24
0 comments:
Post a Comment