>

Friday, November 9, 2012

Factorial Using While loop in java

import java.util.Scanner;

class FactorialWhile{

 public static void main(String args[]){

    int fact=1,num,i=1;

    System.out.println("Enter the number:");

   Scanner in=new Scanner(System.in);

   num=in.nextInt();

  while(i<=num){

    fact=fact*i;

    i++;
}

  System.out.println("factorial of given number is "+fact);
}  }


OUTPUT:

Enter the number:
4
factorial of given number is 24

5 comments:

  1. using Iteration for loop in java what would be the program to run

    a) 1!+2!+3!+4!+5!

    b) 1/1!+2/2!+3/3!+4/4!+5/5!

    c) 1/1!-2/2!+3/3!-4/4!+5/5!

    ReplyDelete
  2. how to create multiple reverse factorial in java ...Example if user input 5 .so 5 of factorial and 4 factorial and 3 ,2,1 . this type give answer..plz help me

    ReplyDelete
  3. How to find the factorial using loop . The output should be in the below form .example 5!
    O/p - 5*4*3*2*1 = (Result).

    Plz tell me how to code this program

    ReplyDelete

Please post your comments. Your comments make us to write more programs for you.