forked from vikas3799/hacktober_2022_4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanish.java
More file actions
41 lines (32 loc) · 749 Bytes
/
anish.java
File metadata and controls
41 lines (32 loc) · 749 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
29
30
31
32
33
34
35
36
37
38
39
40
41
// Java program for the above approach
import java.lang.*;
import java.util.*;
class GFG{
// Function to find a pair in the given
// array whose sum is equal to z
static boolean findPair(int a[], int n, int z)
{
// Iterate through all the pairs
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
// Check if the sum of the pair
// (a[i], a[j]) is equal to z
if (i != j && a[i] + a[j] == z)
return true;
return false;
}
// Driver code
public static void main(String[] args)
{
// Given Input
int a[] = { 1, -2, 1, 0, 5 };
int z = 0;
int n = a.length;
// Function Call
if (findPair(a, n, z))
System.out.println("True");
else
System.out.println("False");
}
}
// This code is contributed by avijitmondal1998