Question
A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits= 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, output the message “Special 2-digit number” otherwise, output the message “Not a Special 2-digit number”.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class program5
{
public static void main(String[] args)
{
int temp=0,sum=0,product=1,num=0,rem=0,finalSum=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number: ");
num = sc.nextInt();
temp=num;
while(temp>0)
{
rem=temp%10;
sum=sum+rem;
product=product*rem;
temp/=10;
}
finalSum = sum + product;
if (finalSum == num)
{
System.out.println(num+" is Special 2-digit number");
}
else
{
System.out.println(num+" is Not a Special 2-digit number");
}
}
}