473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

An application that reads numbers in the range of 0 to 50

12
I'm trying to create an application that reads an arbitrary number of integers that are in the range 0 to 50 and counts how many occurrences of each are entered. At the end of the input processing, I have to print all of the values (including number of occurrences) that were used one or more times.

So far I've set up the scanner, and I had originally thought to use a number of scan.nextInt() in order to calculate each and every one, but I simply can't develop the right counters and link the concepts. Any help would be greatly appreciated!
Feb 26 '08 #1
9 1858
BigDaddyLH
1,216 Expert 1GB
I'm trying to create an application that reads an arbitrary number of integers that are in the range 0 to 50 and counts how many occurrences of each are entered. At the end of the input processing, I have to print all of the values (including number of occurrences) that were used one or more times.

So far I've set up the scanner, and I had originally thought to use a number of scan.nextInt() in order to calculate each and every one, but I simply can't develop the right counters and link the concepts. Any help would be greatly appreciated!
Post your best effort and ask a specific question about it.
Feb 26 '08 #2
JinFTW
12
Post your best effort and ask a specific question about it.
This is how far I've gotten, I realize there are a number of mistakes, but I'm currently working on it.


Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. public class Numbers
  3. {
  4.     public static void main (String[] args)
  5.     {
  6.         Scanner scan = new Scanner (System.in);
  7.         final int MAXNUM = 51;
  8.         int[] list = new int [MAXNUM];
  9.  
  10.         int current=0; 
  11.  
  12.         System.out.println ("Enter a series of numbers between 1 and 50: ");
  13.         int number  = scan.nextInt();
  14.  
  15.         for (int index = 0; index < 50; index++)
  16.         {
  17.             list[index]++;
  18.  
  19.  
  20.  
  21.         }
  22.         for (int index = 0; index < list.length; index++)
  23.         {
  24.             System.out.print ();
  25.  
  26.         }
  27.  
  28.     }
  29. }
Feb 26 '08 #3
BigDaddyLH
1,216 Expert 1GB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Feb 26 '08 #4
BigDaddyLH
1,216 Expert 1GB
Don't forget part B: ask a specific question!
Feb 26 '08 #5
JinFTW
12
I'm simply wondering how you use an array to give the number of occurrences for each integer that the user enters.
Feb 26 '08 #6
BigDaddyLH
1,216 Expert 1GB
I'm simply wondering how you use an array to give the number of occurrences for each integer that the user enters.
Like what you've done, except after you get the verified input -- call it number, you:

Expand|Select|Wrap|Line Numbers
  1. list[number]++;
because list[number] records the count of times number was input (not the best name: "list")
Feb 26 '08 #7
JinFTW
12
Thank you so much! I think I can see where it's going now, much appreciated to you for clearing that up!
Feb 27 '08 #8
JinFTW
12
Ok after adding list[number]++;
and looking at the problem itself, it appears as though I'm only taking in one value from the user. I hate to bother you guys with this, but I suppose I have another question here, do I need another for loop in this statement? Or am I supposed to use an if-else in order to have this thing read the user's answers again and again?
Feb 27 '08 #9
BigDaddyLH
1,216 Expert 1GB
Ok after adding list[number]++;
and looking at the problem itself, it appears as though I'm only taking in one value from the user. I hate to bother you guys with this, but I suppose I have another question here, do I need another for loop in this statement? Or am I supposed to use an if-else in order to have this thing read the user's answers again and again?
How else can you execute something repeatedly?
Feb 27 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Nicholas Geraldi | last post by:
Im looking for a decent random number generator. Im looking to make a large number of random numbers (100 or so, if not more) in a short period of time (as fast as possible). the function i was...
7
by: Leif K-Brooks | last post by:
I'm a newbie at C++, but no stranger to other programming languages. I'm working on my first C++ program (besides "hello world" and the like), and it needs to generate a (pseudo-)random number...
7
by: Tweaxor | last post by:
I stuck with exerise in a Learning C book that I got. If I have the numbers as input. How can I determine which of the three is the smallest number, largest number and the range. Or would it be...
2
by: Kumar | last post by:
Hi Folks, I have a question regarding my windows c# application. This application just reads MS Excel file and puts the data in to sql server database. In that excel file ,it has one named cell...
24
by: Tuvas | last post by:
Okay, I'm working on devoloping a simple, cryptographically secure number, from a range of numbers (As one might do for finding large numbers, to test if they are prime). My function looks like...
8
by: kiranchahar | last post by:
Hey all, How do I generate random numbers with Uniform distribution Uniform(a,b) using C-programming? I want to generate uniform random numbers which have mean following Uniform(p,q) and also...
9
by: MLH | last post by:
A mailing list table in its virgin state contained sequential, consecutive integers in an autonumber field (A97). I've deleted records throughout the table. Now I would like to identify each...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
3
by: djcamo | last post by:
Hi, I have a situation where I have a collection that holds numbers. Mostly they are concurrent eg. 125801-125899 but sometimes they are not eg. 125801-125899, 195301-399. Is there any way to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.