- Factorial Number Using DoWhile Loop(up to n Numbers)
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;
System.out.println(x+" Factorial =" +fact);
x++;
}while(x<=n);
}
}
Output:
Enter n value
5
1 Factorial =1
2 Factorial =2
3 Factorial =6
4 Factorial =24
5 Factorial =120
More Programs visit : http://sateeshm.com/
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;
System.out.println(x+" Factorial =" +fact);
x++;
}while(x<=n);
}
}
Output:
Enter n value
5
1 Factorial =1
2 Factorial =2
3 Factorial =6
4 Factorial =24
5 Factorial =120
More Programs visit : http://sateeshm.com/