First of all, you should first try to make your code readable and maintainable. That's the most important thing. Start by indenting it properly, and give meaningful names to your methods and variables.
Now to the performance, there are many things that can be optimized, but it won't change much, unless this method is called billions of times:
- the local variable should be a constant
- the
str.equals(local) test should be executed once, out of the loop
- you should not use Integer, but int:
int in = arr[i] * 2;
- the multiplication doesn't need to be computed twice
Here's a complete optimized version:
private static final String FIND_NUMBER = "findnumber";
public void q1(String str, int[] arr) {
if (FIND_NUMBER.equals(str)) {
for (int i = 0; i < arr.length; i++) {
int doubleValue = arr[i] * 2;
if (doubleValue > 10) {
System.out.print(doubleValue);
}
}
}
}