-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathp1.java
More file actions
30 lines (26 loc) · 666 Bytes
/
Copy pathp1.java
File metadata and controls
30 lines (26 loc) · 666 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
import java.util.Scanner;
public class p1{
boolean find3Numbers(int A[], int arr_size, int sum) {
int l, r;
for (int i = 0; i < arr_size - 2; i++) {
for (int j = i + 1; j < arr_size - 1; j++) {
for (int k = j + 1; k < arr_size; k++) {
if (A[i] + A[j] + A[k] == sum) {
System.out.print("Triplet is " + A[i] + ", " + A[j] + ", " + A[k]);
return true;
}
}
}
}
return false;
}
public static void main(String[] args) {
p1 triplet = new p1();
int A[] = { 12,3,4,1,6,9};
int sum = 24;
int arr_size = A.length;
triplet.find3Numbers(A, arr_size, sum);
}
}
//.
//.........................