"Design and implement an application that reads a number of integers that are in the range of 0 to 50 inclusive and counts how many times each one is entered. After all input has been processed, print all of the value, with the number of times each was entered."

This is what i have thus far, and being a beginner, i guess (as I have been told) my coding style is a little sloppy. =\.

import java.util.*; public class zerotofifty { public static void main(String[] args){ int number, temp=0; int[][] numbers = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; boolean valid = false, same = false; Scanner input = new Scanner(System.in); System.out.println("Please enter 30 numbers in the range of 0 to 50"); for (int i = 0; i < numbers.length; i ++) { //set valid to false so we can actually get back into the while //after the user successfully enters an integer valid=false; //check to see if number entered is valid, if not, repeat! while (!valid) { number = input.nextInt(); if (number < 0 || number >50) {valid = false; System.out.println("Please enter a number that IS BETWEEN (inclusive) 0 AND 50!!!");} else {valid = true; numbers[0][i] = number;} } } //once done entering numbers, let's sort it using insertion sort! for(int index = 1; index < numbers.length; index++) { int key = numbers[0][index]; int position = index; //shift larger values to the right while(position > 0 && numbers[0][position-1] > key) { numbers[0][position]= numbers[0][position-1]; position--; } numbers[0][position] = key; } for (int i = 0; i < numbers.length-1; i++) { for (int x = 1; x < numbers.length; x++) { //add for an occurrence of the new number, then goto the 'same loop' to see if there are any others temp++; same = true; //check for more equal integers while (same) { if (numbers[0][i] == numbers[0][x]) temp++; //if not equal to each other, set the field below it equal to the number of occurrences in the entire array else {numbers[1][i] = temp; temp = 0; i=x;} } } //once done counting, lets print out the info. for (int i1 = 0; i1 <numbers.length; i1++) { if(numbers[1][i1] != 0) System.out.println(numbers[0][i1]+": "+numbers[1][i1]+" times."); } } } }

I've stepped through this with the debugger in Eclipse countless times. It seems that when i enter an integer out of the range after entering an integer within the range, and then i proceed to enter an integer within the range, it just hangs on

number = input.nextInt();

any ideas? Maybe its going into some hidden ultra-crazy infinite loop?

This post has been edited by **sethkrepps**: 04 November 2009 - 04:57 PM