-
Notifications
You must be signed in to change notification settings - Fork 0
/
BouncyNumber.java
28 lines (28 loc) · 1.01 KB
/
BouncyNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
public class BouncyNumber {
public static void main(String[] args) {
System.out.print("Enter a number : ");
Scanner sc=new Scanner(System.in);
String num=sc.next();
if(num.length()<=2) {
System.out.println("A number below 100 can never be a Bouncy number.");
return;
}
int a=num.charAt(0),i;
for(i=1;i<num.length();i++)
if(a>num.charAt(i))
break;
if(i==num.length())
System.out.println("It is not a Bouncy number because the digits are sorted in ascending order.");
else{
for(i=1;i<num.length();i++) {
if(a<num.charAt(i))
break;
}
if(i==num.length())
System.out.println("It is not a Bouncy number because the digits are sorted in descending order.");
else
System.out.println("It is a Bouncy number because the digits are unsorted.");
}
}
}