BASIC JAVA PROGRAM OF FACTORIAL

//java program of factorial---

PROGRAM CODE---

class factorial{ void fact(int no) { int i,f=1;
for(i=1;i<=no;i++) { f=f*i; } System.out.println("factorial of given num is"+f); }}class callfact{ public static void main(String ar[]) { factorial f1=new factorial(); f1.fact(5); }
}



OUTPUT OF ABOVE PROGRAM----





DESCRIPTION::

  •  create a class name factorial ----> there a method fact which is responsible for factorial of a given number...and print it.

  • create a main class callfact ---> In this class create a object of factorial class and access method of factorial class by using object and also pass a number which we want to do factorial....






Comments