/****** 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 */
Labels: Core Java
Subscribe to:
Post Comments (Atom)
frnd these programs are simply super did u realy did this all
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!!!
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
/*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);
}
}
/*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);
}
}
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);
}
}