forked from uiuxarghya/NumberPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bouncy_23.java
49 lines (49 loc) · 1.46 KB
/
Bouncy_23.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.*;
class Bouncy_23
{
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("N = ");
int n = Integer.parseInt(br.readLine());
if(n < 0){
System.out.println("Not an increasing number.");
System.out.println("Not a decreasing number.");
System.out.println("Not a bouncy number.");
return;
}
if(isIncreasing(n))
System.out.println(n + " is an increasing number.");
if(isDecreasing(n))
System.out.println(n + " is a decreasing number.");
if(!isIncreasing(n) && !isDecreasing(n))
System.out.println(n + " is a bouncy number.");
}
public static boolean isIncreasing(int num){
int last = num % 10;
boolean status = true;
while(num != 0){
int digit = num % 10;
if(digit > last){
status = false;
break;
}
last = digit;
num /= 10;
}
return status;
}
public static boolean isDecreasing(int num){
int last = num % 10;
boolean status = true;
while(num != 0){
int digit = num % 10;
if(digit < last){
status = false;
break;
}
last = digit;
num /= 10;
}
return status;
}
}