【问题标题】:my code work at eclipse but does not work at android studio how to fix我的代码在 eclipse 上工作,但在 android studio 上不工作 如何修复
【发布时间】:2017-06-01 02:54:41
【问题描述】:

公共类 DemoWebBrowser { 公共静态 void main(String args[]) {

    String answer = "A. hold - read";
     String answerQuestion = "";

     String[] arrStr1 = answer.split("\\.");
        String str1 = arrStr1[1];
            String[] Str2 = str1.split("-");
            answerQuestion = "Jeff _____ a book right now, he _____ a story to Linda.";
            for (int i = 1 ; i < Str2.length +1 ; i++){
                answerQuestion = answerQuestion.replaceFirst("_____",Str2[(i-1)]);
            }



                System.out.println( answerQuestion);


            }
   }

问题出在哪里?我该如何解决?

【问题讨论】:

  • 跟安卓有什么关系?
  • 提供无效的细节。
  • 那么,什么不起作用?另外,清理你的缩进。
  • 我想从字符串“Jeff _____ 现在一本书,他 _____ 给 Linda 讲一个故事”中替换元素“______”。由从字符串 "A. hold - read" 中拆分出来的多个元素组成。我像上面一样编码,但它在 android studio 中不起作用,但当我检查时它在 eclipse 中起作用。

标签: android eclipse


【解决方案1】:

试试这个代码

 String answer = "A. hold - read";
 String answerQuestion = "";

 String[] arrStr1 = answer.split("\\.");
    String str1 = arrStr1[1];
        String[] Str2 = str1.split("-");
        answerQuestion = "Jeff _____ a book right now, he _____ a story to 
        Linda.";
        for (int i = 0; i < Str2.length(); i++){
            answerQuestion = answerQuestion.replaceFirst("_____",Str2[i]);
        }
        System.out.println( answerQuestion);
        }

}

【讨论】:

  • 成功了!非常感谢兄弟!但是我还是没看清楚。
  • 你在你的代码中忘记了 '()' simvols,但我不知道它在 eclipse 上是如何工作的
猜你喜欢
  • 2015-11-06
  • 1970-01-01
  • 2022-07-17
  • 2012-12-01
  • 1970-01-01
  • 2016-12-22
  • 1970-01-01
  • 2012-07-02
  • 1970-01-01
相关资源
最近更新 更多