Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Task28 {
- public static void findSecondMax(int[] a) {
- int max = a[0];
- for (int i = 0; i < a.length; ++i) {
- if (max < a[i]) {
- max = a[i];
- }
- }
- boolean check = true;
- int secondMax = 0;
- for (int i = 0; i < a.length; ++i) {
- if (a[i] < max) {
- if (check) {
- secondMax = a[i];
- check = false;
- } else {
- if (a[i] > secondMax) {
- secondMax = a[i];
- }
- }
- }
- }
- if (!check) {
- System.out.println(secondMax);
- }
- }
- }
Add Comment
Please, Sign In to add comment