I struggled with a question that I am trying to solve in preparation for testing, and I thought I could use your help. I need to write a Boolean method that takes an array of integers (positive and negative), and returns true, if the array can be divided into two groups equally , the number of all group numbers are equal to each group. For exmaple for this array:
int[]arr = {-3, 5, 12, 14, -9, 13};
The method will return true since -3 + 5 + 14 = 12 + -9 + 13.
For this array:
int[]arr = {-3, 5, -12, 14, -9, 13};
The method will return false, because even if -3 + 5 + 14 + -12 = -9 + 13, the number of numbers in each part of the equation is not equal.
For an array:
int[]arr = {-3, 5, -12, 14, -9};
The method will return false since the length of the array is not defined.
, , , .
, , , , .
- -, .
!