Monday, July 27, 2020

Write a program to input a number and check whether it is Spy Number or not? (123 = 1+2+3 = 6 , 1*2*3 = 6 , 6=6)

53)  Write a program to input a number and check whether it is Spy Number or not? (123 = 1+2+3 = 6  , 1*2*3 = 6 , 6=6)

import java.util.*;
public class Spy_number
{
    public static void main(String args[ ])
   {
          Scanner sc = new Scanner (System.in);
          System.out.println("Enter a number");
          int p = sc.nextInt();
          int s = 0;
          int x = 1;
          while(p>0)
          {
          int d = p%10;
          s=s+d;
          x=x*d;
          p=p/10;
          }
          if(x==s)
          {
              System.out.println("Entered number is a SPY number");
          }
          else
          {
              System.out.println("Entered number is not a SPY number");
          }
   }
}

Output : 

No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj