How can I change my code to find all possible number combination where addition of number is equal to some input number.
Example data
We have array [1,4,6,8,9,12,17,19,21,28,45,67,.....,n]
and input number 29
Expect result is
(Sum of multiple value from array that equal to x)
[1,28]
[8,21]
[1,9,19]
....
My current code is
int [] number = new int[]{1,5,8,12,15,18,20,24,28,30};
int expectValue = 25;
for (int i = 0; i < number.length-1 ;i++){
for (int j = i+1; j < number.length; j++){
if(number[i] + number[j] == expectValue){
System.out.println("["+number[i]+","+number[j]+"]");
}
}
}
Result
[1,24][5,20]