Peterson Number in Java
In this section, we will learn what is Peterson number and how can we check whether a given number is Peterson or not through a Java program.
A number is said to be Peterson if the sum of factorials of each digit is equal to the sum of the number itself.
Steps to Find Peterson Number
Example of Peterson Number
Suppose, we have to check the number (n) 145 is Peterson or not.
Number = 145
145 = !1 + !4 + !5
We observe that the number and the sum of factorials of digits are equal to the number itself. Hence, 145 is a Peterson number.
Let's implement the above logic in a Java program.
Peterson Number Java Program
In the following program, we have taken an array of factorial to quickly find the factorial. You can use the logic also.
Enter a number to check: 145 The given number is a Peterson number.
Enter a number to check: 773 The given number is not a Peterson number.
Next TopicSunny Number in Java