Increasing and Decreasing Number in Java
Increasing and Decreasing Number in Java
Question : Write a program to check whether a number is Increasing Number or Decreasing Number?
Increasing Number : In an integer traversing from left to right if the current digit is greater than or equal to the previous digit, the number is known as increasing numbers.
Ex : 23689
Decreasing Number : In an integer traversing from left to right if the current digit is less than the previous digit, the number is known as decreasing numbers.
Ex : 98632
Note : A number which is neither increasing nor decreasing is Bouncy Number.
* To understand the program clearly watch this video : Increasing/Decreasing Number in Java
Program to check Increasing/Decreasing Number:-
Program :-
import java.io.*;
import java.util.*;
class IncreasingorDecreasing
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n,p,a=0,b=0,x=0,y=0,d,sd;
System.out.println("Enter Number");
n=in.nextInt(); //Input Number
p=n; //Copy of Input Number
while(n>9)
{
d=n%10;
sd=(n%100)/10;
n=n/10;
if(((d>sd) || (d==sd)) && (b==0) && (y==0))
{
a=1;
x=1;
continue;
}
else if((d<sd || d==sd) && (a==0) && (x==0))
{
b=1;
y=1;
continue;
}
else
{
a=2;
b=2;
break;
}
}
if(a==1)
{
System.out.println("It is an Increasing Number : "+p);
}
else if(b==1)
{
System.out.println("It is a Decreasing Number : "+p);
}
else
{
System.out.println("It is neither increasing nor decreasing Number : "+p);
}
}//end of main method
}// end of class
For Proper Understanding Watch the Video :-
All the best :)
Keep Learning :)
Comments
Post a Comment