我不明白为什么它不能检测到这个脚本下面的" + "符号,请帮助。
public class Main {
public static void main(String[] args) {
String r_text = "10 + 10 + 10";
String count = "";
for (int i = 0; i < r_text.length(); i++){
Object x = r_text.charAt(i);
String c = x.toString();
if (c != "+"){
System.out.println(c);
}
}
}
}
正确的格式是:
public class Main {
public static void main(String[] args) {
String r_text = "10 + 10 + 10";
String count = "";
for (int i = 0; i < r_text.length(); i++){
char x = r_text.charAt(i);
if (x != '+'){
System.out.println(x);
}
}
}
}