Examples of Loops: Part 2

Learn about the ‘for’ and ‘while’ loops in more detail with the help of the examples in this lesson.

Coding example: 66

In the following example, we can examine whether the user’s input number is a special number or not. A number is said to be a special number when the sum of the factorial of its digits is equal to the number itself. For example, 145 is a special number as 1! + 4! + 5! = 145. If you want to rerun the code, write java main in the terminal:

Get hands-on with 1400+ tech skills courses.