## Introduction to Mystery Number

The Mystery number is defined as a number which we get by sum up of two the numbers and that two numbers should be the reverse of each other, this is a unique number, to find that number must be of two digits, then break the number into two numbers such as ‘A’ and ‘B’, if the digit of ‘A’ is reverse of ‘B’ or the digit of ‘B’ is reverse of ‘A’, then that number is said to be a Mystery number, to get this number split the number into two number in which the unit digit and tens digits are interchanged.

### Logic behind Mystery Number

In the above introduction, we saw that a number is said to be a Mystery number if that number can be got by sum up of the two numbers and that two numbers must be reverse of each other, and that number may lie between 22 and 198 because these are the multiples of 11 in the decimal numeration.

Let us see the logic behind using decimal numeration.

If a number is split into two digits numbers so that its unit digit and ten digits are interchanged or reversed then we have to use logic as given below.

- Suppose N is a unit digit and M is a 10-digit then the original number will be 10M+N
- If we interchange the unit and tens place, then we get 10N+M
- Then we get a number i.e., hence we can write it as Mystery number = 10M+N+10N+M
- By solving the above, we get the equation as 11M+11N
- 11 is common in above, so take it common, hence we get 11(M+N)
- In this case, M and N can be replaced by any whole number, also we can say that we can use this case when the condition is given in a two-digit number.

Let us see some examples by using the above equation.

Put the values of M and N in the above equation.

11(5+3) = 88 = 44 + 44

11(2+9) = 121 = 29 + 92

11(8+3) = 121 = 38 + 83

11(6+5) = 121 = 65 + 56

11(2+2) = 44 = 22 + 22

In this way we can find the number.

### How to Check Mystery Number?

- If we have a number first check that number must be a two-digit number.
- Then break that number into two numbers, and two numbers which we get that also be two-digit numbers.
- After that check whether the digit of one number is the exact reverse of the second number or we can say that numbers digits must be interchanged.
- If two numbers are in reverse of each other, then that number is a Mystery number, otherwise, it is not.

### Examples of Mystery Number

Given below are the examples mentioned:

#### Example #1

Java program to check whether the given number.

**Code:**

`import java.util.*;`

class Mysterynumber

{

static int revers(int m)

{

int sum=0,rem;

while(m!=0)

{

rem=m%10;

sum=sum*10+rem;

m=m/10;

}

return sum;

}

public static void main(String[] args)

{

int num,i,f=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter any number :");

num=sc.nextInt();

for(i=1;i<num;i++)

{

if(i+revers(i)==num)

{

System.out.println("This is a Mystery number");

f=1;

break;

}

}

if(f==0)

System.out.println("This is not a Mystery number");

}

}

**Output:**

In the above example, we have written java code to check the entered number. For that, we take a class ‘Mysterynumber’ and defined one method ‘revers()’ to reverse the given value and used while loop for a condition if that condition is true then it will return the yes it is a Mystery number if the condition is false then returns that is not and to import of package is also necessary, as we have done at the first line of the program. In main() method called the defined functions to check a number is a Mystery number or not. The screenshot is given for the reference of the output.

#### Example #2

Java program to check the Mystery number with its two sum up number with reverse.

**Code:**

`import java.util.Scanner;`

public class MystNumber

{

static int reverse(int a)

{

String strn = Integer.toString(a);

String string="";

for(int i=strn.length()-1;i>=0;i--)

{

string=string+strn.charAt(i);

}

int rev=Integer.parseInt(strn);

return rev;

}

static boolean MystNum(int num)

{

for (int z=1; z <= num/2; z++)

{

int y = reverse(z);

if (z + y == num)

{

System.out.println( z + " " + y);

System.out.println(num+ " is a mystery number.");

return true;

}

}

System.out.println("The given number is not a mystery number.");

return false;

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter a number: ");

int num = sc.nextInt();

MystNum(num);

}

}

**Output:**

In the above example, we have written a java program to check the given number is Mystery or not with its sum up of two numbers as shown in the above screenshot. For the writing program, we take a class ‘MystNumber’, and define a static function to reverse the given number, in that took a string to convert the number into a string that string has been stored and reverse of the string also been stored. Define a function to check by reversing and comparing two numbers put a print statement to show two numbers which get from a given number, put conditions to check the given number if the condition is true then it will show the given number is a mystery number and if condition false then returns this is not a mystery number.

### Conclusion

In the above article we conclude that this is a unique number and to find it we must have to follow conditions, and if conditions are true then and then only we will get that number, some logic and steps are explained in this article which will help to find the Mystery number.

### Recommended Articles

This is a guide to Mystery Number. Here we discuss the introduction, logic, how to check mystery number? and examples respectively. You may also have a look at the following articles to learn more –

41 Online Courses | 13 Hands-on Projects | 322+ Hours | Verifiable Certificate of Completion

4.5

View Course

Related Courses