Factorial Number Using DoWhile Loop

 

  • Factorial Number Using DoWhile Loop

import java.util.Scanner;


public class Demo {


public static void main(String[] args) {

int x=1,n,fact=1;

Scanner s=new Scanner(System.in);

System.out.println("Enter n value");

n=s.nextInt();

do

{

fact=fact*x;

x++;

}while(x<=n);

System.out.println(fact);

}



}


Output:

Enter n value

5

120

More Programs visit : http://sateeshm.com/

No comments:

Post a Comment