Another one for you guys if you want to help me out... This program is supposed to print the maximum and minimum value in an array. It doesn't. There's a problem in my logic and I cannot figure it out! I've been staring at it too long.
I'm new to Java, that's why all these are pretty simple to you gurus... thoughts?
EDIT: I lied, I wanted first and second maximum numbers. Sorry :$
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, second; // 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 = 1; while (index > a.length) { if (a[index] < first) { second = first; first = a[index]; } else { if (a[index] < second) { second = a[index]; } } index = index + 1; } System.out.println("The maximum number is " + first); System.out.println("The second number is " + second); } }