Hi, I wrote this code, but the last part I did it by trial and error and by seeing something similar. I don't understand how to print the number of occurrences. I did it, but I don't understand why I had to put " if (array[i] > 0) "
/*PP 8.1 Design and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times. */ import java.util.*; public class arbArray { public static void main(String[]args) { final int FINAL=51; int[] array = new int[FINAL]; Scanner scan = new Scanner(System.in); for (int i = 0; i < array.length; i++) { System.out.println("Enter a number for location "+i+":"); int n = scan.nextInt(); while (n < 0 || n > 50) { System.out.println("Please enter a number between 0 and 50 for location "+i+" :"); n = scan.nextInt(); } array[n]++; } for (int i = 0; i < array.length; i++) { if (array[i] > 0) { System.out.println(i + ": " + array[i]); // Print the number of occurrences for the numbers entered. } } } }