JavaAlgorithms/Others/Abecedarian.java

25 lines
523 B
Java
Raw Normal View History

package Others;
2017-09-29 06:49:28 +08:00
/**
* An Abecadrian is a word where each letter is in alphabetical order
*
* @author Oskar Enmalm
*/
class Abecedarian {
public static boolean isAbecedarian(String s) {
2017-09-29 06:49:28 +08:00
int index = s.length() - 1;
for (int i = 0; i < index; i++) {
2017-09-29 06:49:28 +08:00
if (s.charAt(i) <= s.charAt(i + 1)) {
} //Need to check if each letter for the whole word is less than the one before it
2017-09-29 06:49:28 +08:00
else {
return false;
2017-09-29 06:49:28 +08:00
}
}
return true;
}
}