Write a Java-program to print Factorial of upto N Numbers using do while loop ?

Write a Java-program to print Factorial of upto N Numbers using do while loop ?

Program
```public class Main
{
public static void main(String args[])
{
int x=1,n=5,fact=1;
do
{
fact=fact*x;
System.out.println(x+" Factorial is "+fact);
x++;
}while(x<=n);

}
}
```

Output:

1 Factorial is 1
2 Factorial is 2
3 Factorial is 6
4 Factorial is 24
5 Factorial is 120

Using CommandLine Arguments
```public class Main
{
public static void main(String args[])
{
int x=1,n,fact=1;
n=Integer.parseInt(args[0]);
do
{
fact=fact*x;
System.out.println(x+" Factorial is "+fact);
x++;
}while(x<=n);

}
}
```

Output:

1 Factorial is 1
2 Factorial is 2
3 Factorial is 6
4 Factorial is 24
5 Factorial is 120

Using Scanner Class
```import java.util.*;
public class Main
{
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 is "+fact);
x++;
}while(x<=n);

}
}
```

Output:

Enter n value : 5
1 Factorial is 1
2 Factorial is 2
3 Factorial is 6
4 Factorial is 24
5 Factorial is 120