You are on page 1of 2

package orgStructureServerWar;

public class FindSum {


public static void main(String args[]) {
int a[] = { 2, 10, 20, 22 };
boolean val = getSum(a, 5, 0, a.length - 1);
System.out.println(val);
}
public static boolean getSum(int a[], int sum, int l, int r) {
if (l != r) {
if (a[l] + a[r] == sum) {
System.out.println(a[l] + "\t" + a[r]);
return true;
}
else if (a[l] + a[r] < sum) {
l++;
} else {
r--;
}

return getSum(a, sum, l, r);


}
return false;

package orgStructureServerWar;
public class FindSum {
public static void main(String args[]) {
int a[] = { 21,32,31, 12,33, 24, 22,40 };
findSecond(a);
}
public static void findSecond(int a[]) {
int first = a[0];
int sec = first;
for (int i = 0; i <=a.length - 1; i++) {
if (a[i] > first) {
sec = first;
first = a[i];
} else if (a[i] > sec && sec < first) {
sec = a[i];
}
// System.out.println(first+"\t"+sec);
}

System.out.println(sec + "" + first);


}
}

You might also like