-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSum.java
More file actions
33 lines (26 loc) · 774 Bytes
/
TwoSum.java
File metadata and controls
33 lines (26 loc) · 774 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
public class TwoSum {
static boolean checksum (int[] arr , int target) {
for (int i=0; i < arr.length; i++) {
for (int j=i+1; j < arr.length; j++) {
int sum = arr[i] + arr[j];
if (sum == target){
return true;
}
}
}
return false;
}
public static void main (String[] args) {
//declare the array
int[] arr = {11,22,33,44,55,66,77,88,99,100};
//declare the target
int target = 132;
TwoSum twosum = new TwoSum();
boolean result = twosum.checksum(arr,target);
if (result) {
System.out.println("Numbers found ");
} else {
System.out.println("Numbers not found");
}
}
}