Friday, December 30, 2016

Factorial program using java

Factorial : In mathematics the factorial is a non-negative integer n,denoted by n!,is the product of all positive integers less then or equal to n.



For Example :

5!=5*4*3*2*1=120


Example of Factorial using java :


class Myfact{
        public static void main(String args[]){
                 int i,fact=1,n=5;
                 for(i=1;i<=5;i++){
                      fact=fact*i;
                 }
                 System.out.println("Factorial is: "+fact);
        }
}

Output: 

Factorial is: 120

No comments:

Post a Comment

how to add watermark in movavi video editor | movavi watermark | how to ...

What is static keywords in java ? static keywords in java is a main topic of java.