Skip to content

Instantly share code, notes, and snippets.

@PramodDutta
Created October 5, 2025 05:11
Show Gist options
  • Select an option

  • Save PramodDutta/657853dbf41510dd5654beae440fc203 to your computer and use it in GitHub Desktop.

Select an option

Save PramodDutta/657853dbf41510dd5654beae440fc203 to your computer and use it in GitHub Desktop.
2nd High number in aRRAY
class Main {
public static void main(String[] args) {
int[] numbers = {-12, 45, 67, 23, 89, 45 89};
int highest = Integer.MIN_VALUE;
int secondHighest = Integer.MIN_VALUE;
for (int num : numbers) {
if (num > highest) {
secondHighest = highest;
highest = num;
} else if (num > secondHighest && num != highest) {
secondHighest = num;
}
}
System.out.println(secondHighest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment