如何尽可能优化此功能
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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是相当奇怪的代码,但它是相同的.
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);
}
}
Run Code Online (Sandbox Code Playgroud)