これで、値 8 の 3 つの整数すべてを 7 に置き換えたいのですが、出力では 7 が 1 つしか得られません...
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;
}
}