Page 167 - CA_Blue( J )_Class10
P. 167
You will get the following output:
Program 6 To input a number and print the factorial of the number using while loop.
1 import java.util.*;
2 class while_loop
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int i=1,n,f=1;
8 System.out.print("Enter a number : ");
9 n=sc.nextInt();
10 while(i<=n)
11 {
12 f=f*i;
13 i++;
14 }
15 System.out.println("Factorial of a number : "+f);
16 }}
You will get the following output:
165
Iterative constructs in Java 165

