I’ll probably get down voted for providing an answer, because you are providing no clear question, and you aren’t showing any effort to solve your problem yourself before the community helps you.
What I’m able to decipher from your sample result is there is no need for ArrayList
if you’re given two inputs m
and n
.
From your inputs, take the largest number and run a loop from 1 to that number. Subtract that number from your sum and check if that difference is greater than 0 and less than the other number. If that’s true you have a way to compute the sum of 10.
Something like:
public class StackOverflow {
public static void main(String args[]) {
int m = 7;
int n = 5;
int sum = 10;
// Take the larger of the two inputs
int limit = m > n ? m : n;
int count = 0;
for (int i = 1; i <= limit; i++) {
int possibleN = sum - i;
// Check that the possibleN is greater than 0 and less than n
if (0 < possibleN && possibleN <= n) {
System.out.printf("%d + %d = %d\r\n", i, possibleN, sum);
count++;
}
}
System.out.printf("There are %d ways to get %d\r\n", count, sum);
}
}
Results:
5 + 5 = 10
6 + 4 = 10
7 + 3 = 10
There are 3 ways to get 10
1
solved Adding two arrays together to find the numbers of possible combinations of 10 [closed]