Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Number Frequency with Arrays

$
0
0
Here is the assignment:
Design and implement an application that reads a number of integers that are in the range 0 to 50 inclusive and counts how many times each one is entered. After all input has been processed, print all of the values, with the number of times each one was entered.
Test Data: User enters 10 numbers ( 21, 1, 45, 49, 30, 18, 1, 21, 6, 40,
18, 49, 10, 49, 12)
//Imports the Scanner class for user input
import java.util.Scanner;
 public class ArrayProblem1
{
	public static void main (String [] args)
	{
		//Initializes scanner for user input
		Scanner in = new Scanner (System.in);
		//Initalizes an array with 10 integers
		int frequency [] = new int [51];
		int count = 0;
		for (int b = 0; b < 10; b ++)
		{
			//Asks the user to enter in ten numbers with a range from 0 to 50
			System.out.println ("Enter in ten numbers with a range from 0 to 50 :");
			int output = in.nextInt ();
			frequency [input] = count + 1;


			}
	for (int y = 0; y < 51; y ++)
 		{
		System.out.println (y + " appears " + frequency [y] + " time(s) ");
			}
		}
	}



My problem is that if I enter in a number more then once, the output for that number shows that I only entered the number once.


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>