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 digits = 5 * 9 = 45
Total of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept only 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, display the message "Special 2 - digit number" otherwise, display
the message "Not a special two-digit number"
Answers
Answered by
24
Answer:
Program:-
import java.util.*;
public class Special
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int n,num=0,a=0,s=0,p=1;
System.out.println("Enter the two digit number");
n=in.nextInt();
num=n;
while(n!=0)
{
a=n%10;
s=s+a;
p=p*a;
n=n/10;
}
if((s+p)==num)
System.out.println(num + " is a special two digit number");
else
System.out.println(num + " is not a special two digit number");
}
}
Similar questions