Write a java program to show a special two digit number is such that when the sum of its digit is added to the product of its digit. The result is equal to the original number.
( e.g. - Consider the Number = 59
Sum of the digit = 5+9 = 14
Product of the digit = 5*9 = 4 Sum = 45+14 = 59= the number considered
Answers
Answer:
import java.util.*;
public class java1
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int p=1,s=0,r,n,t;
System.out.println("enter a no.");
n=sc.nextInt();
while(n>0)
t=n;
{
r=n%10;
s=s+r;
p=p*r;
n=n/10;
}
if((s+p)==t)
{
System.out.println(t+"IT IS A SPECIAL TWO DIGIT NUMBER");
}
else
{
System.out.println(t+"IT IS NOT A SPECIAL NUMBER");
}
}
}
}
please mark BRAINLIEST♥♥
Answer:
import java.io.*;
class GFG
{
// function to find if number
// is special or not
static void specialNumber(int n)
{
// Checking whether entered
// number is 2 digit or not
if(n < 10 || n > 99)
System.out.println("Invalid Input! " +
"Number should have " +
"2 digits only");
else
{
// Finding the first digit
int first = n / 10;
// Finding the last digit
int last = n % 10;
// Finding the sum
// of the digits
int sum = first + last;
// Finding the product
// of the digits
int pro = first * last;
if((sum + pro) == n)
{
System.out.println(n + " is a Special" +
" Two-Digit Number");
}
else
{
System.out.println(n +" is Not a Special" +
" Two-Digit Number");
}
}
}
// Driver Code
public static void main(String args[])
{
int n = 59;
specialNumber(n);
}
}