Sunday, 8 January 2012

Factorial value Program

java factorial program code
The below  is java factorial program code,how to find out a factorial of a number,factorial of a number in java,factorial program in java,factorial program
The below is java factorial program code


import java.io.*;
class Fact{
  public static void main(String[] args) {
      try{
        BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter the number");
        int a= Integer.parseInt(object.readLine());
        double fact= 1;
        System.out.println("Factorial of " +a+ ":");
        for (int i= 1; i<=a; i++){
              fact=fact*i;
        }
        System.out.println(fact);
    }
    catch (Exception e){
        System.out.println("Array out of bounds exaception");
    }
  }
}

OUTPUT:

C:\>d:

D:\>cd javaprog

D:\javaprog>javac Fact.java

D:\javaprog>java Fact
enter the number:5
the factorial value
120.0















No comments:

Post a Comment