A Program That Takes Number As Input And Prints It's Factorial - HelpMeOutAlways

Tuesday, February 19, 2019

A Program That Takes Number As Input And Prints It's Factorial

Source code


import java.util.Scanner;

class FactorialProgram
{

public void fact ()
  {
 
int i, fact = 1;
 
Scanner Sc = new Scanner (System.in);
 
System.out.println ("Enter any number to find it's Factorial");
 
int number = Sc.nextInt ();
 
for (i = 1; i <= number; i++)
      {

fact = fact * i;
   

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

}


}

class Main{

public static void main (String args[]){
 
FactorialProgramobj = new FactorialProgram
();
 
obj.fact ();

}
}

Output

java program

1 comment:

  1. you have created such a nice blog which helped me alot.

    ReplyDelete

@way2themes