# Really need some help on school

• 10-22-2013, 12:41 AM
supernowlin
Really need some help on school
This is the question and what I have so far. I would love some help for this one.

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. Stop reading input when any integer outside the range 0 to 50 is encountered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times.
Prompt for input with System.out .print("enter numbers: ").
The output should be one frequency count per line. For example:
enter numbers: 2 2 5 5 5 5 5 5 2 5 -1
3 occurrences of 2
7 occurrences of 5

//Samuel Tate
//Itec 120
//Frequnency
// Will not complile

import java.util.Scanner;

public class Frequency {

public static void main (String[] args) {

int input = 0;
int[] integers = new int[51];
Scanner scan = new Scanner(System.in);

while(input != 51); {

System.out.print("Enter an arbitrary number of integers in the range 0-50 (enter 51 to exit) : ");
input = scan.nextInt();
if(input == 51) break;
if(input < 0 || input > 50){
System.out.println("number out of range");
}
integers[input]++;
continue;

}

for(int index = 0; index < 51; index++);
if(integers[index] > 0)
System.out.println(index + ": " + integers[index]);

}

}
• 10-22-2013, 12:56 AM
jim829
Re: Really need some help on school
Well, for one thing your while loop has a dangling semicolon after it. You need to remove it. Same for you for loop at the end. I am not certain about
what you are trying to accomplish with the termination logic. Does an input value of 51 cause the loop to exit? And the continue statement at the
end of the while loop is unnecessary.

Regards,
Jim
• 10-22-2013, 05:26 AM
Junky
Re: Really need some help on school
The exact same advice offered in duplicate post