Factorial Program in Java

Advertisements

Prev Tutorial Next Tutorial

Java Program to Find Factorial on Number

Factorial of any number is the product of an integer and all the integers below it for example factorial of 4 is 4! = 4 * 3 * 2 * 1 = 24. In below code i will show you how to design Java program to find factorial, using for loop you can perform this task.

Factorial Program in Java

import java.util.Scanner;
class Factorial
{
	public static void main(String[] args) 
	{
    int no, fect=1;
	Scanner s=new Scanner(System.in);
    System.out.println("Enter any number :");
	no=s.nextInt();
    for(int i=1; i<=no; i++)
	{
	fect=fect*i;
	}
	System.out.println("Factorial is :" +fect);
	}
}

Output

Enter any number :
6
Factorial is :
720

Syntax to compile and run java program

Syntax

for compile -> c:/>javac Factorial.java
for run -> c:/>java Factorial

Explnation of Code

  • Scanner s=new Scanner(System.in): are used for receive input from keyboard.
  • nextInt(): method are used for get integer type value from keyboard.
  • System.out.println("....."): are used for display message on screen or console.

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223
wifi cctv camera

Wifi CCTV Camera RS:1200 to 2499. Contact no. 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements