// This program prints the maximum and the second maximum elemnet in an array
class A3Q3b
{
public static void main (String[] args)
{
// DECLARE VARIABLES/DATA DICTIONARY
int [] a; // GIVENS: the array of values
// int index; // INTERMEDIATES: index through array
int first = 0;
int second = 0; // RESULTS: values of Max and Second Max
System.out.println( "Please input the array: " );
a = ITI1120.readIntLine();
// BODY OF ALGORITHM
// first = a[0]; second = a[0];
//index = 0;
for (int i = 0; i < a.length; i++)
{
if (a[i] > first)
{
second = first;
first = a[i];
}
}
for (int j = 0; j < a.length; j++)
{
if (first > a[j])
{
second = a[j];
}
}
//index ++;
System.out.println("The maximum number is " + first);
System.out.println("The second number is " + second);
}
}