-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP15.java
More file actions
31 lines (27 loc) · 777 Bytes
/
P15.java
File metadata and controls
31 lines (27 loc) · 777 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
27
28
package Assignment2;
class P15 {
static void findTriplets(int arr[],
int n, int target)
{
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] == target) {
System.out.println(
arr[i] + " " + arr[j]
+ " " + arr[k]);
}
}
}
}
}
public static void main(String[] args)
{
int arr[] = { 3, 1, 2, 9, 7, 5, -1, 6};
int n = arr.length;
findTriplets(arr, n, 9);
}
}