Hi, does anyone know what is wrong here? The program is supposed to find the largest number entered, and the 2nd largest number entered. The process for assigning the 2nd largest is not working, I do not think I am evaluating it correctly, and suggestions?
package random;
import java.util.Scanner;
public class random23 {
public static void main(String[] args) {
int number;
int largest = 0;
int largestSoFar = 0;
int secondLargest = 0;
Scanner input = new Scanner(System.in);
for(int count = 0; count < 10; count++){
System.out.print("Enter a number: ");
number = input.nextInt();
if (number > largestSoFar){
largestSoFar = number;
}
if (count == 9) {
largest = largestSoFar;
System.out.println(largest);
}
if (number <= largest){
if (number > secondLargest){
secondLargest = number;
}
}
System.out.print("------------------------ \n");
}
System.out.printf("Largest# = " + largest + "\n");
System.out.printf("Second Largest# = " + secondLargest + "\n");
}
}