Question: Consider the following code: int f(int[] a, int[] b) { int sum = 0; for (int i = 0; i < a.length; i++) sum +=a[i];


Consider the following code:

int f(int[] a, int[] b) { int sum = 0;

for (int i = 0; i < a.length; i++) sum +=a[i]; for (int j = 0; j < b.length; j++) sum +=b[j]; returnsum;

}


a. Which code smellis present in this code? (Choose exactly one.)

[ ]duplicatecode [ ] long parameterlist [ ]longmethod [ ]none

b. Which refactoring would you choose to eliminate the smell (Choose exactlyone.)

[ ]extractmethod [ ] introduce parameterobject [ ] replace method withmethodobject [ ] nonerequired

c. What will the code look like after the refactoring (ifrequired):


Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a The code smell present in this code is duplicate code becaus... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!