KatsolAgency

Programming languages and web development including java , html, css ,java script,Tutorials Android phone tricks and Tech news around the world.

Saturday, July 29, 2017

Program2 Factorial of a number

Program2 - Factorial of a number


This simple java program it shows how to calculate
Factorial of a number.

public class NumberFactorial {
public static void main(String[] args) {
int number = 5;
/*
* Factorial of any number is! n.
* For example, factorial of 4 is 4*3*2*1.
*/
int factorial = number;
for(int i =(number - 1); i > 1; i--)

{
factorial = factorial * i;
}
System.out.println("Factorial of a number is " + factorial);
}
}


Output of the Factorial program would be
Factorial of a number is 120
NEXT

    Choose :
  • OR
  • To comment
No comments:
Write comments