//find nd greatest among n numbers

import java.util.Scanner;

public class Numbers {

    public static void main(String[] args) {
        int n, temp, max = Integer.MIN_VALUE, secondMax = Integer.MIN_VALUE;
        Scanner ip = new Scanner(System.in);
        System.out.print("Enter the number of inputs: ");
        n = ip.nextInt();
        for (int i = 1; i <= n; i++) {
            System.out.print("Enter number " + i + ": ");
            temp = ip.nextInt();
            if (temp >= max) {
                secondMax = max;
                max = temp;
            } else if (temp >= secondMax)
                secondMax = temp;
        }
        System.out.println("The greatest number is " + max);
        System.out.println("The second greatest number is " + secondMax);
        ip.close();
    }

}



OUTPUT:
Enter the number of inputs: 7
Enter number 1: 11
Enter number 2: 67
Enter number 3: 23
Enter number 4: 98
Enter number 5: 32
Enter number 6: 45
Enter number 7: 76
The greatest number is 98
The second greatest number is 76
12-21 02:32