package strings;/*** <p>* Alphabetical order is a system whereby character strings are placed in order* based on the position of the characters in the conventional ordering of an alphabet.* </p>* Wikipedia: https://en.wikipedia.org/wiki/Alphabetical_order*/class Alphabetical {public static void main(String[] args) {assert !isAlphabetical("123abc");assert isAlphabetical("aBC");assert isAlphabetical("abc");assert !isAlphabetical("xyzabc");assert isAlphabetical("abcxyz");}/*** Check if a string is alphabetical order or not** @param s a string* @return {@code true} if given string is alphabetical order, otherwise {@code false}*/public static boolean isAlphabetical(String s) {s = s.toLowerCase();for (int i = 0; i < s.length() - 1; ++i) {if (!Character.isLetter(s.charAt(i)) || !(s.charAt(i) <= s.charAt(i + 1))) {return false;}}return true;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。