Advertisement
eldieck

Untitled

Mar 11th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public class Lab4Try2 {
  2.  
  3. public static final int[] array = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 5 };
  4.  
  5. public static void main(String[] args) {
  6. System.out.println(determinePossibleNumbers(7));
  7.  
  8. }
  9.  
  10. public static long determinePossibleNumbers(int matches) {
  11. long count = 0L;
  12.  
  13. count += countNumbers(true, matches - 4);
  14.  
  15.  
  16. return count;
  17. }
  18.  
  19. public static long countNumbers(boolean first, int matches) {
  20. long count = 0L;
  21. boolean notFirst = false;
  22.  
  23. if(first){
  24. if(matches - array[0] >= 0){
  25. count++;
  26. count += countNumbers(notFirst, matches - array[0]);
  27. }
  28. }
  29. else {
  30. for (int j = 1; j < array.length; j++) {
  31. if (matches - array[j] >= 0) {
  32. count += countNumbers(notFirst, matches - array[j]);
  33. count++;
  34. }
  35. }
  36.  
  37. }
  38. return count;
  39.  
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement