1.

⇒ Write a program to check whether a number is a spy number or not. (A number is a spy if the sum of all the digits is equal to the product of its digits) ⇒ Ex: If n=1124 (1+1+2+4=1*1*2*4)

Answer»

ogram:package com.company; import java.util.Scanner; class Main {    public STATIC void main(STRING[] args) {        Scanner SC = new Scanner (System.in);        System.out.println("Enter a NUMBER: ");        long n = sc.nextLong();        long a, s = 0, p = 1;        while (n>0) {            a = n%10;            s=s+a;            p=p*a;            n=n/10;        }        if (s==p){            System.out.println("Number is a Spy number.");        }        else {            System.out.println("Number is not a Spy number.");        }    } }



Discussion

No Comment Found