Bouncy Number

 ✹ Bouncy Number is one in which is a non-negative integer, and it is neither an increasing number, nor a decreasing number.

Example:          264458 (Bouncy Number)
                            123559 (Not a Bouncy Number because it’s follow the Increasing trend)
                            76210 (Not a Bouncy Number because it’s follow the Decreasing trend)

import java.util.Scanner;

class Bouncy_Number
{
    public static void main (String args[])
    {
        int c=0, n,r,i=0, j=0,c1=0,c2=0,temp, max=0, min=9;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the Number = ");
        n=sc.nextInt();
        temp=n;
        //Count the Number of Digit
        while (temp>0)
        {
            c++;
            temp/=10;
        }
        if(c>=3)//Checking Number of Digit
        {
            while(n>0) //Loop will be executed till the value of n is greater the 0
            {
                r=n%10;  // Extract digit from right
                //Check Increasing Trend
                if(r>=max)
                {
                    max=r;
                    c1++;
                }
                //Check Decreasing Trend
                if(r<=min)
                {
                    min=r;
                    c2++;
                }
                n=n/10;
             }
            //Check Increasing & Decreasing Trend
            if(c==c1|| c==c2)
                System.out.println("Not Bouncy No");
            else
                System.out.println("Bouncy No");
        }
        else
             System.out.println("The Number is not a 3 digit number");
    }
}

No comments

Powered by Blogger.