I am having a problem comparing last two alphabetic letters of a single string in alphabetical order. I know how to compare two strings alphabetically using compareTo()
string function but no idea about this.
This is what I have to do :
Method isIncreasing()
to check whether the given string is an increasing string or not. It is increasing if, while moving from Left to Right, each character in the string comes after the previous character in the alphabetical order.
Example: ANT
is an increasing string whereas APPLE
is not.
I won't do your homework for you, but here's an outline to get you started:
char
variable called for instance last
to hold the previous letter. '\\0'
String.toCharArray
) last
您可以编写一个Comparator来覆盖compare方法,以比较for。循环中每个受Math.min(o1.length,o2.length)限制的字母的短值字母(只是强制转换为short)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.