我希望这将所有三个值 8 的整数替换为 7。但输出只给我一个 7...
public class hore {
public static void main(String[] args) {
int[] list = {8, 9, 8, 6, 9, 8};
int number = count(list, 8, 7);
System.out.print(number);
}
public static int count(int[] list, int target, int replacement) {
for (int n : list) {
if (n == target) {
n = replacement;
}
}
return replacement;
}
}