Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int[] a = new int[n];
- for (int i = 0; i < n; i++) {
- a[i] = in.nextInt();
- }
- int max1 = a[0], max2 = a[1];
- for (int i = 0; i < n; i++) {
- if (max1 < a[i]) {
- max2 = max1;
- max1 = a[i];
- } else if (max2 < a[i]) {
- max2 = a[i];
- }
- }
- int temp;
- if (max2 > max1) {
- temp = max2;
- max2 = max1;
- max1 = temp;
- }
- System.out.print(max1 + " " + max2);
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement