# Thread: Really need some help on school

1. Member
Join Date
Oct 2013
Posts
3
Rep Power
0

## 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]);

}

}

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## 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

3. ## Re: Really need some help on school

The exact same advice offered in duplicate post

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Really need some help on school

Another waste of my time. Maybe this time the advice will sink in.

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•