Created
October 5, 2025 05:11
-
-
Save PramodDutta/657853dbf41510dd5654beae440fc203 to your computer and use it in GitHub Desktop.
2nd High number in aRRAY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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