Peterson Number

Peterson Number is a number whose sum of factorial to it’s digits are equal to the original number.

Example 1: 145. 1!+4!+5! = 1+24+120 = 145. Hence it is a Peterson Number.

Example 2: 415. 4!+1!+5! = 24+1+120 = 145. Here the result is not equal to the original number. Hence it is not a Peterson Number.

Java
import java.util.*;
public class PetersonNumber
{
    public static void main(String args[])
    {
        int n=0,s=0,r=0,fact=1,nCopy=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a number: ");
        n=sc.nextInt();
        nCopy=n;
        while(n>0)
        {
            r=n%10;
            while(r>0)
            {
                fact=fact*r;
                r--;
            }
            s=s+fact;
            fact=1;
            n=n/10;
        }
        if(s==nCopy)
        {
            System.out.println(nCopy+" is a Peterson Number");
        }
        else
        {
            System.out.println(nCopy+" is not a Peterson Number");
        }
    }
}
Java