can someone please solve this java program
Answers
Answer:
import java.util.Scanner;
class SpyNumber
{
public static void main(String[] args)
{
//Declaration
Scanner input = new Scanner(System.in);
int n1, n2;
int remainder, product, sum, temp1, temp2;
//Prompt and accept 2 numbers from user
System.out.println(“Enter two integers: ”);
n1 = input.nextInt();
n2 = input.nextInt();
//Initialization
remainder = 0;
sum = 0;
temp1 = n1;
temp2 = n2;
product = 1;
//Check whether n1 is a spy number
if (n1 > n2)
{
System.out.println(“Invalid Input”);
System.exit(0);
}
if (n1 < n2)
{
for (int i = 1; i <= n1; i++)
{
remainder = n1 % 10;
sum = sum + remainder;
product = product * remainder;
n1 = n1/10;
}
}
if (sum == product)
{
System.out.println(n1 + “ is a spy number);
}
}
}