It is asked to re-engineering this two Java classes in order to avoid code duplication and improve maintainability.
public class Adder {
public int sum(int[] array) {
int result = 0;
for (int i = 0; i < array.length; i++) {
result += array[i];
}
return result;
}
public class Multiplier {
public int multiply(int[] array) {
int result = 1;
for (int i = 0; i < array.length; i++) {
result *= array[i];
}
return result;
}
Pay attention to different result
initialization; it's my main problem.
Aucun commentaire:
Enregistrer un commentaire