## Factorial

6 comments - Post a comment

/****** Simple Java Program For Factorial ********/
import java.io.*;
class Fact
{
public static void main(String args[])throws IOException
{
int a = 1,n,i;
System.out.print("Enter The Number Whoes Factorial Is To Be Found : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
for(i=n;i>0;i--)
{
a = a * i;
}
System.out.println("Factorial of "+n +" is "+a);
}
}
/*********** OUTPUT **********
Enter The Number Whoes Factorial Is To Be Found : 5
Factorial of 5 is 120 */

This Post has 6 Comments Add your own!
Anonymous - February 14, 2011 at 9:34 PM

frnd these programs are simply super did u realy did this all

Saleem J. Kachemela - May 30, 2011 at 5:37 PM

these programs are owesome bro!! i wanna know more about programming brother, i just wish u could teach me so that i become a programmer. I am a university student taking informatics but i don't know programming, would you mind teaching me
my mail is "sakachemela@yahoo.co.uk". i'l b happy if you assist me on this!!!

Suvam - June 3, 2012 at 2:24 PM

Ausumn job bro...

Can you please explain me the throws exception handling that has been used in the program...

My Email_id: suvampatwari53@gmail.com

Symas - October 7, 2012 at 7:05 PM

/*Another simple Example given by me */
import java.util.Scanner;
public class facto
{

public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.println("enter the number");
int number=scan.nextInt();
int factorial=number;
for(int i=(number-1);i>1;i--)
{
factorial=factorial*i;
}
System.out.println("factorial of number is="+factorial);
}
}

Symas - October 7, 2012 at 7:06 PM

/*great dude
here is another demo of factorial */
import java.util.Scanner;
public class facto
{

public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.println("enter the number");
int number=scan.nextInt();
int factorial=number;
for(int i=(number-1);i>1;i--)
{
factorial=factorial*i;
}
System.out.println("factorial of number is="+factorial);
}
}

Symas - October 7, 2012 at 7:07 PM

import java.util.Scanner;
public class facto
{

public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.println("enter the number");
int number=scan.nextInt();
int factorial=number;
for(int i=(number-1);i>1;i--)
{
factorial=factorial*i;
}
System.out.println("factorial of number is="+factorial);
}
}