Explain the while.. End while loop with an example.
Answers
Answered by
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
Math,
5 months ago
English,
5 months ago
Math,
10 months ago
Accountancy,
10 months ago
Math,
1 year ago