Home » Java programs

Java program to check Spy number

A number is a Spy number, if sum and product of all digits are equal. In this java program, we are going to check whether a given number is SPY number or not?
Submitted by IncludeHelp, on October 29, 2017

Given a number, and we have to check whether it is Spy number or not using Java program.

Spy Number

A number is a Spy number, if sum and product of all digits are equal.


Number 123 is a Spy number, sum of its digits is 6 (1+2+3 =6) and product of its digits is 6 (1x2x3 = 6), sum and product are same, thus, 123 is a spy number.

Program to check Spy number in java

import java.util.Scanner;

public class SpyNumber 
	public static void main(String[] args)
		int n,product=1,sum=0;
		int ld;

		// create object of scanner.
		Scanner sc = new Scanner(System.in);

		// you have to enter number here.
		System.out.print("Enter the number :" );

		// read entered number and store it in "n".

		// calculate sum and product of the number here.

		// compare the sum and product.
			System.out.println("Given number is spy number");
			System.out.println("Given number is not spy number");


First run:
Enter the number :1124
Given number is spy number

Second run:
Enter the number :1123
Given number is not spy number

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.