Computer Science, asked by shaikasifahamed7045, 10 months ago

Explain the while.. End while loop with an example.

Answers

Answered by ritikrao178
3

Answer:

the second loop available in Java is the while loop. The while loop is an entry-controlled loop. The syntax of a while loop is :

              while(expression)

                 loop body

Example :

1. Code to calculate the factorial of an integer using a while loop ?

Answer:

  factorial is to be calculated is stored in variable num

long i = 0 , fact = 1;

i = num;

while(num != 0) {

fact = fact*num;

- - num;

}

System.out.println("The factorial of" + i + "is" + fact);

For num= 5, the above code will print:

Explanation:

Similar questions