Skip to content

Instantly share code, notes, and snippets.

@c0rp-aubakirov
Last active July 13, 2016 17:16
Show Gist options
  • Save c0rp-aubakirov/28e83bdbdf0f448aff042728d6cd43c7 to your computer and use it in GitHub Desktop.
Save c0rp-aubakirov/28e83bdbdf0f448aff042728d6cd43c7 to your computer and use it in GitHub Desktop.
boolean consecutiveAscending = true;
boolean consecutiveDescending = true;
// Check to see if the newPin is made up of consecutive numbers in
// ascending order
for (int j = 0; j < newPin.length() - 1; j++) {
if (Convert.toLong(newPin.substring(j, j + 1)) == null
|| Convert.toLong(newPin.substring(j + 1, j + 2)) == null) {
consecutiveAscending = false;
break;
}
int current = Integer.parseInt(newPin.substring(j, j + 1));
int next = Integer.parseInt(newPin.substring(j + 1, j + 2));
if ((current + 1) != next) {
consecutiveAscending = false;
break;
}
}
if (consecutiveAscending) {
throw new SmartPinConsecutiveException();
}
// Check to see if the newPin is made up of consecutive numbers in
// descending order
for (int j = 0; j < newPin.length() - 1; j++) {
if (Convert.toLong(newPin.substring(j, j + 1)) == null
|| Convert.toLong(newPin.substring(j + 1, j + 2)) == null) {
consecutiveDescending = false;
break;
}
int current = Integer.parseInt(newPin.substring(j, j + 1));
int next = Integer.parseInt(newPin.substring(j + 1, j + 2));
if ((current - 1) != next) {
consecutiveDescending = false;
break;
}
}
if (consecutiveDescending) {
throw new SmartPinConsecutiveException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment