>
Showing posts with label factorial using while loop. Show all posts
Showing posts with label factorial using while loop. Show all posts

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