- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
public static boolean isBouncy(long n) {
boolean isBouncy = false;
String num = Long.toString(n);
String[] seperateDigits = new String[num.length()+1];
for (int i=1; i <= num.length(); i++) {
seperateDigits[i] = num.substring(i-1,i);
}
int firstDig = Integer.parseInt(num.substring(0,1));
int cDig;
int iDeg = 0;
int cDeg = 0;
int dig0;
int dig1;
for (int i = 2; i <= seperateDigits.length-1; i++) {
if (!isBouncy) {
dig0 = Integer.parseInt(seperateDigits[i-1]);
dig1 = Integer.parseInt(seperateDigits[i]);
if (i == 2) iDeg = getDegree(dig0, dig1);
else {
cDeg = getDegree(dig0,dig1);
if (iDeg == 0) iDeg = cDeg;
else if (cDeg == -iDeg) isBouncy = true;
}
}
}
if (iDeg == 0) isBouncy = false;
return isBouncy;
}