- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumChecker.java
More file actions
Latest commit
33 lines (21 loc) · 668 Bytes
/
Copy pathSumChecker.java
File metadata and controls
33 lines (21 loc) · 668 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
packagePractice;
publicclassSumChecker {
//solve to index of position whose sum adds upto target (target =8 then sol is (0,2) as 7+1=8))
staticvoidLogic(intarr[], inttarget) {
intsum;
for (inti=0;i<arr.length-1;i++)
{
for(intj=i+1;j<arr.length;j++) {
sum=arr[i]+arr[j];
if(sum == target )
System.out.println("\nSolution for target "+target+" is "+i+","+j); }
}
}
publicstaticvoidmain(String[] args) {
System.out.println("Given Numbers-");
intarr[]=newint[] {1,3,7,2,9,4};
for(intval:arr)
System.out.print(val+",");
Logic(arr, 10);// give target as second argument here
}
}