Spy Numbers

Given a starting number and the ending number the task is to find the all the Spy Number present in that given range and also to display it’s frequency.

Spy Number is a number whose sum of digits and product of digits are equal.

Example 1: 22. 2+2 = 2*2 = 4. Hence it is a Spy Number.

Example 2: 44. 4+4 ≠ 4*4. Here the sum of digits is not equal to the product of digits. Hence it is not a Spy Number.

Java
import java.util.*;
public class SpyNumberRange
{
    public static void main(String args[])
    {
        int start=0,end=0,r=0,s=0,p=1,n=0,frequency=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a starting range: ");
        start=sc.nextInt();
        System.out.print("Enter a ending range: ");
        end=sc.nextInt();
        System.out.println("Spy Numbers in the given range: ");
        for(int i=start;i<=end;i++)
        {
            n=i;
            while(n>0)
            {
                r=n%10;
                s=s+r;
                p=p*r;
                n=n/10;
            }
            if(s==p)
            {
                System.out.println(i);
                frequency++;
            }
            s=0;p=1;
        }
        System.out.print("Frequency: "+frequency);
    }
}
Java