Computer Science, asked by zoya6843, 11 months ago

Start with 2 int arrays, a and b, each length 2. Consider the sum of the values in each array. Return the array which has the largest sum. In event of a tie, return a.

Answers

Answered by Anonymous
0

Problem:

Start with 2 int arrays, a and b, each length 2. Consider the sum of the values in each array. Return the array which has the largest sum. In event of a tie, return a.

biggerTwo({1, 2}, {3, 4}) → {3, 4}

biggerTwo({3, 4}, {1, 2}) → {3, 4}

biggerTwo({1, 1}, {1, 2}) → {1, 2}

Solution:

public int[] biggerTwo(int[] a, int[] b) {

if (b[1] + b[0] > a[1] + a[0])

return b;

else

return a;

}

Answered by Theking256
0

Answer:

hope this answer useful to you mate

Attachments:
Similar questions