-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ13.java
More file actions
26 lines (24 loc) · 783 Bytes
/
Q13.java
File metadata and controls
26 lines (24 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.net.Inet4Address;
import java.util.ArrayList;
public class Q13 {
public static void main(String[] args) {
ArrayList<Integer> l = new ArrayList<> ();
System.out.println (sumsubquence(new int[]{1 ,2, 3 ,4 ,5} , 0 , l , 0 ));
}
private static int sumsubquence(int[] ints , int sum , ArrayList l , int idx) {
int add = 5;
int count = 0;
if(idx >= ints.length){
if(add == sum){
System.out.println (l);
return 1;
}
return 0 ;
}
l.add (ints[idx]);
int i = sumsubquence (ints , sum+ ints[idx] , l , idx + 1 );
l.remove (l.size () - 1);
int j = sumsubquence (ints , sum , l , idx + 1);
return i + j ;
}
}