Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have written this program and it does what it should do, however each time I r

ID: 3637767 • Letter: I

Question

I have written this program and it does what it should do, however each time I run it it gives me this error :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 51
at intCount.main(intCount.java:40)
and I don't know why or how to fix it. I am hoping someone can help.

The assignment is this:

Design and implement an application that reads an arbitrary number of intergers that are in the range of 0 to 50 inclusive and counts how many occurrences of each are entered. After all input had been processed, print all of the values (with the number of occurrences) that were entered one or more times:

Below is my program:

import java.io.*;
import java.util.Scanner;

public class intCount
{
public static void main (String[] args) throws IOException
{
final int MAX = 50;
final int MIN = 0;

Scanner input = new Scanner (System.in);

int[] count = new int[MAX+1];

for (int i=0; i<count.length; i++)
{
count[i] = 0;
}

System.out.println ("Enter a series of integers between 0 and 50 in value");
System.out.println ("Begin entering:");
int n = input.nextInt();

while (n >=MIN && n<=MAX)
{
count[n] = count[n] + 1;

System.out.println ("Continue entering numbers");
n = input.nextInt();
}

System.out.println ("The count of integers is:");

for (int i=0; i<=count.length; i++)
{
if (count[i] > 0)


System.out.println (i + " " + count[i]);
}
}
}

Thank you very much in advance

Explanation / Answer

import java.util.Scanner; public class SevenPtOne { public static void main(String[] args){ int x; Scanner readMe = new Scanner(System.in); System.out.println("Enter couple numbers from 0-50"); readMe.nextInt(); for (int i = 0; i <args.length;i++) { x = Integer.parseInt(args[i]); // not really sure if i understand the question all the way but heres what i have so far // i know i need another for loop but not sure what im checking for..help plz         }     } }