Tuesday, March 15, 2022

Mystery Number Checking Using BlueJ Program

A mystery number is a number that can be expressed as the sum of two numbers and those two numbers should be the reverse of each other.

Examples:

Input : n = 121 

Output : 29 92

Input : n = 22 

Output : 11 11


import java.util.*;
class Str3
{
   Scanner sc=new Scanner(System.in);
    void main()
    {
       int a,b,i,n;
       System.out.print("\nEnter any number: ");
       n=sc.nextInt();
       b=n-1;       
           
       for(i=1;i<=n/2;i++)
       {
           if(i==rev(b))
           break;
           b--;
        }
        if(i<=n/2)        
        System.out.println("Mystery Number");   
          else
        System.out.println("Not Mystery Number");
    }
   
private int rev(int n)
{
     int r=0;
     while(n>0)
     {
         r=r*10+n%10;
         n=n/10;
        }
        return r;
    }
    public static void main(String args[])
    {
        Str3 ob=new Str3();
        ob.main();
    }
}       

  Other Programs On Numbers: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner