Okay I've got a homework assignment to write a program that reads integers, finds the TWO (2) largest of them, and counts their occurrences. I've managed to get the largest number but can I get any tips on how to find the second largest?
Here is my code so far and thanks in advance!
import java.util.Scanner; public class Unit4PT1 { public static void main (String [] args){ Scanner in = new Scanner(System.in); System.out.print("Enter numbers: "); int max = -1; int count = 0; int number; while((number = in.nextInt()) != 0){ if(number > max){ max = number; count = 1; } else if (number == max){ count++; } } System.out.println("The largest number is " + max); System.out.println("The occurence count of the largest number is " + count); } }