【问题标题】:I don't get it Why it can't detect “+” symbol [duplicate]我不明白为什么它无法检测到“+”符号[重复]
【发布时间】:2021-12-07 20:24:52
【问题描述】:

我不明白为什么它无法检测到此脚本下方的“+”符号请帮助。

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);
            }
        }
    }
}

【问题讨论】:

    标签: java string for-loop if-statement detection


    【解决方案1】:

    这是正确的形式:

    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);
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2018-05-22
      • 2023-03-22
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      相关资源
      最近更新 更多