Programming Examples

Java program to input a number and check whether it is special two digit number or not


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-digitnumber” otherwise,

output the message “Not a special2-digit number”.

Solution

import java.util.*;
class TwoDigitSpecial
{
	public static void main(string arr[])
	{
		Scanner sc=new Scanner(System.in);
		int n,f,l;
		System.out.println(“Enter a 2 digit number”);
		n=sc.nextInt();
		if(n>=10 && n<=99)
		{
			f=n/10;
			l=n%10;
			if(f+l+f*l==n)
				System.out.println(“Special 2-digit number”);
			else
				System.out.println(“Not a Special 2-digit number”);
		}
		else
			System.out.println(“Not a 2-digit number”);
	}
}
Output

Enter a 2 digit number : 79

Output : Special 2-digit number

-------------------------------------------------

Enter a 2 digit number : 47

Output : Not a Special 2-digit number

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad