Showing posts with label Spy Number. Show all posts
Showing posts with label Spy Number. Show all posts

Spy Number

 //Wap to accept a number and check whether it is a Spy Number or not.

// A number is spy if the sum of its digits equal the product of its digits.

//example 1124 

//sum of the digits = 1+1+2+4=8

//product of the digits = 1x1x2x4=8

//8==8 so, 1124 is a spy number

import java.util.*;

class spy

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        int n,r,pro=1,sum=0;

        System.out.println("Enter a number:");

        n=sc.nextInt();

        while(n>0)

        {

            r=n%10;

            sum=sum+r;

            pro=pro*r;

            n=n/10;

        }

        if(sum==pro)

        System.out.println("It is a Spy number");

        else

        System.out.println("It is not a Spy number");

    }

}

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...