Write a java 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".
Answers
ANSWER:
import java.io.*;
class Special
{
void display ()throws IOException
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println("Enter a two digit no.");
n = Integer.parseInt(br.readLine());
if(n>=10&&n<=99)
{
b=n%10;
s=s+b;
p=p*b;
n=n/10;
}
if(s+p==n)
{
System.out.println("Special 2-digit number");
}
else
{
System.out.println("Not a Special 2-digit number");
}
}
}
}
Hope it helps...
Mark as Brainliest Please
Answer:
import java.util.Scanner;
public class KboatSpecialNumber
{
public void checkNumber() {
Scanner in = new Scanner(System.in);
System.out.print("Enter a 2 digit number: ");
int orgNum = in.nextInt();
int num = orgNum;
int count = 0, digitSum = 0, digitProduct = 1;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}
if (count != 2)
System.out.println("Invalid input, please enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit number");
}
}
Explanation: