Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ArrayOfCounters {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int input;
- int[] frequencyCounter = new int[51];
- do {
- System.out.print("Enter an integer between 0 and 50, inclusive: ");
- input = scanner.nextInt();
- if (input > -1 && input < 51) {
- frequencyCounter[input]++;
- }
- } while (input > -1 && input < 51);
- for (int i=0; i<frequencyCounter.length; i++) {
- if (frequencyCounter[i] > 0) {
- System.out.println(i + " : " + frequencyCounter[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment