【发布时间】:2012-10-27 23:40:29
【问题描述】:
我正在尝试编写一个程序来读取字符串并比较字符串中的每个字符以查看它是否按字母顺序排列。
public class Main
{
public static void Main ( String[] args)
{
System.out.println("#Please enter the string: ");
String s = BIO.getString();
while(!s.equals("END")){
int length = s.length();
String sLC = s.toLowerCase();
int count = 0;
boolean inOrder = true;
for(int i = 0; i < length - 1 ; i++){
if(sLC.charAt(i).compareTo(sLC.charAt(i+1)) > 0) {
inOrder = false;
break;
}
}
System.out.println("#Please enter the string: ");
s = BIO.getString();
}
}
}
我正在使用 blueJ,当我尝试编译它时,它给了我错误 'char cannot be dereferenced and highlighting the 'compareTo' method in my IF statement?
【问题讨论】: