首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何优化这个函数?

如何优化这个函数?
EN

Stack Overflow用户
提问于 2012-09-26 23:26:11
回答 4查看 162关注 0票数 0

如何尽可能优化这个函数?

代码语言:javascript
运行
复制
public void r1(String st1, int[] ar1) {
    String inox = "newsearch";
    for (int j = 0; j < ar1.length; j++) {
        if (st1.equals(inox) && ar1[j] * 2 > 20) {
            Integer intx = new Integer(ar1[j]);
            intx = intx * 2;
            System.out.print(intx.toString());
        }
    }
}
EN

回答 4

Stack Overflow用户

发布于 2012-09-26 23:30:18

这是一个相当奇怪的代码,但它与。

代码语言:javascript
运行
复制
public void r1(String st1, int[] ar1) {
    if (!str1.equals("newsearch")) return;

    for (int j : ar1) {
        int j2 = j * 2;
        if (j2 > 20) 
            System.out.print(j2);
    }
}
票数 6
EN

Stack Overflow用户

发布于 2012-09-26 23:30:09

代码语言:javascript
运行
复制
public void r1(String st1, int[] ar1) {
    String inox = "newsearch";
    if (st1.equals(inox) {
        for (int j = 0; j < ar1.length; j++) {
             if (ar1[j] > 10) {
                System.out.print(ar1[j] * 2);
            }
        }
    }
}
票数 0
EN

Stack Overflow用户

发布于 2012-09-26 23:32:14

代码语言:javascript
运行
复制
public void r1(String st1, int[] ar1) {
  if (st1.equals("newsearch") {
    for (int j = 0; j < ar1.length; j++) {
      if (ar1[j] > 10) {
        System.out.print(ar1[j] * 2);
      }
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12605202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档