Write a program in java to accept an integer input and check whether the number input is a spy number or not and display the output.

THE FOLLOWING PROGRAM SEGMENT SHOWS HOW T O CHECK FOR A SPY NUMBER AND PRINT IT IN JAVA.

import java.util.*;

class SPYNUMBER

{

    public static void main (String args[])

    {

        Scanner ob = new Scanner (System.in);

        System.out.println("Enter a number to check");

        int num = ob.nextInt();// to store the num//

        int sum = 0;// to store the sum

        int pro = 1; // to store the product

        int a; // storing each extracted digit

        int p = num;  // creates a backup of input

        while(num != 0)

        {

            a = num %10;

            sum+= a;

            pro *= a;

            num = num/10;

        }

        System.out.println("The sum is  = "+sum );

        System.out.println("The product is = " +pro);

        if( sum == pro)

        {

            System.out.println("The number is a spy number ");

        }

        else

        {

            System.out.println("The number is not a spy number");

        }

    }

    }

Hope you guys found it helpful.

Please share it with your friends and comment down in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such updates.

Visit us again.

Thank you!!

        

 

Comments

Popular Posts