️️️❌
public class TrickyCode {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 30;
int result = multiply(add(a, b), c);
System.out.println("结果:" + result);
}
public static int add(int x, int y) {
return x + y;
}
public static int multiply(int x, int y) {
int result = 0;
while (y != 0) {
if (isEven(y)) {
x = add(x, x); // 错误的乘法操作
y = divideByTwo(y);
} else {
result = add(result, x);
y = subtract(y, 1);
}
}
return result;
}
public static boolean isEven(int number) {
return number % 2 == 0;
}
public static int divideByTwo(int number) {
return number / 2;
}
public static int subtract(int x, int y) {
return x - y;
}
}