-
Notifications
You must be signed in to change notification settings - Fork 0
/
arr13.java
43 lines (33 loc) · 874 Bytes
/
arr13.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//TRIPLET & TRIPLET SUM COUNT
package Array;
public class arr13 {
// program to print all possible triplet of array element
public static void printAllTriplet(int arr[]) {
int n=arr.length;
for(int i=0; i<n-2; i++) {
for(int j=i+1; j<n-1; j++) {
for(int k=j+1; k<n; k++) {
System.out.println("("+arr[i]+","+arr[j]+","+arr[k]+")");
}
}
}
}
// find no of count of triplet sum is equal to x
public static int tripletSum(int arr[], int x) {
int n=arr.length;
int count=0;
for(int i=0; i<n-2; i++) {
for(int j=i+1; j<n-1; j++) {
for(int k=j+1; k<n; k++) {
if(arr[i]+arr[j]+arr[k]==x) {
count++;
}
}
}
}
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}