0% found this document useful (0 votes)
5 views2 pages

BufferZero Code Review Insights

This document contains code to find the second largest number in an integer array. It defines a main method that takes an integer array as input and calls the findSecond method. The findSecond method initializes first and sec variables to the first element of the array. It then iterates through the array, updating first and sec to track the largest and second largest numbers. Finally, it prints the second largest number followed by the largest number.

Uploaded by

lonesarir
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

BufferZero Code Review Insights

This document contains code to find the second largest number in an integer array. It defines a main method that takes an integer array as input and calls the findSecond method. The findSecond method initializes first and sec variables to the first element of the array. It then iterates through the array, updating first and sec to track the largest and second largest numbers. Finally, it prints the second largest number followed by the largest number.

Uploaded by

lonesarir
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

package orgStructureServerWar;

public class FindSum {


public static void main(String args[]) {
int a[] = { 2, 10, 20, 22 };
boolean val = getSum(a, 5, 0, [Link] - 1);
[Link](val);
}
public static boolean getSum(int a[], int sum, int l, int r) {
if (l != r) {
if (a[l] + a[r] == sum) {
[Link](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 <=[Link] - 1; i++) {
if (a[i] > first) {
sec = first;
first = a[i];
} else if (a[i] > sec && sec < first) {
sec = a[i];
}
// [Link](first+"\t"+sec);
}

[Link](sec + "" + first);


}
}

You might also like