0

如何尽可能优化这个功能

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

4 回答 4

6

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

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);
    }
}
于 2012-09-26T15:30:18.297 回答
0
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);
            }
        }
    }
}
于 2012-09-26T15:30:08.893 回答
0
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);
      }
    }
  }
}
于 2012-09-26T15:32:13.500 回答
0

建立在 Peter Lawreys 版本之上:

public void r1(String st1, int[] ar1) {
    if (!str1.equals("newsearch"))
        return;
    for (int j : ar1)
        if (j > 10)
            System.out.print(j << 1);
}
于 2012-09-26T15:39:26.350 回答