Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Lab4Try2 {
- public static final int[] array = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 5 };
- public static void main(String[] args) {
- System.out.println(determinePossibleNumbers(7));
- }
- public static long determinePossibleNumbers(int matches) {
- long count = 0L;
- count += countNumbers(true, matches - 4);
- return count;
- }
- public static long countNumbers(boolean first, int matches) {
- long count = 0L;
- boolean notFirst = false;
- if(first){
- if(matches - array[0] >= 0){
- count++;
- count += countNumbers(notFirst, matches - array[0]);
- }
- }
- else {
- for (int j = 1; j < array.length; j++) {
- if (matches - array[j] >= 0) {
- count += countNumbers(notFirst, matches - array[j]);
- count++;
- }
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement