Thursday, 18 July 2024

SuperSpy Number ICSE Computer Science

A number is called SuperSpy if the sum of the digits equals the product of the digits.

Example:

123 is a SuperSpy number

1+2+3 = 6

1*2*3 = 6

Below is the code for determining if a number is SUPERSPY.

import java.util.Scanner;
class SuperSpy
{
    public static void main(String[]args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number");
        int num = sc.nextInt();
        int sum = 0,temp = num, product = 1;
        while(temp>0)
        {
            int digit=temp%10;
            sum = sum+digit;
            product = product*digit;
            temp/=10;
        }
        if(sum == product)
        {
            System.out.println(num+" is a SuperSpy number");
        }
        else
        {
            System.out.println(num+" is not a SuperSpy number");
        }
    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.