Results 1 to 8 of 8
Thread: generating random integers
- 10-16-2012, 11:00 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
generating random integers
So far in my java programming class i have been doing well, but i have a new assignment that is due this friday october 19th i've been trying to figure it out for many hours now and i am stumped. we are using eclipse IDE. this is my assignment:
Problem to Solve
This assignment is to solve problem using loops. Write a program to generate 100 random integers
in the range of 0 and 99999, and the frequency count of each digit (0, 1, 2, . . . , 9) in these numbers,
and print a frequency histogram.
How to Do It:
The Overall program structure may look like this:
1. Use ten variables for the frequency counts for the ten digits 0, 1, 2, . . . , 9.
2. Other variables are also needed. For example, a variable to hold a random number, a variable
for the digit, etc.
3. Repeat 100 times (a loop):
Generate a random number.
For each digit d in the number, increase the frequency count of d by 1. This is done
using a loop. Note: we do not know how many digits are in the number.
4. For each digit from 0 to 9 (a loop):
Store its frequency count into a variable.
Display the digit and the frequency count.
Display the horizontal frequency bar of asterisks using a loop.
To accomplish the task, Here are some suggestions:
1. Generate random integers in the range [0, 99999]. Assume the variable is number:
number = (int)(Math.random() * 99999);
2. Get the digits of the random number. Since we do not know how many digits in the number,
you need to use a loop to "peel off" the rightmost digit one at a time using integer division
(/) and modulus (%) operations.
i need help on how to begin this program
if anyone can help me i will be much appreciative of it because i have been very very busy and stressed lately and i need these points for this assignment or at least some points.
thank you,
-AlexLast edited by javaFREEK; 10-16-2012 at 11:06 PM.
- 10-17-2012, 01:55 AM #2
Re: generating random integers
The same way you start any other program: import statements followed by class header. Actually the best place to start is with a piece of paper and start sketching out some ideas of what variables you will need, what methods you will need and the general flow of the program.
People are willing to help but you need to make it easy as possible for us. As you post stands it is simply a "Here's my assignment. Give me the code" type of post.if anyone can help me i will be much appreciative of it because i have been very very busy and stressed lately and i need these points for this assignment or at least some points.
If you want our help you need to make an attempt. Write some code. Post it here and include full error messages if you get them. Most importantly of all - ask a specific question. "I don't know how to do me assignment" is not specific and not a question.
- 10-17-2012, 01:59 AM #3
Re: generating random integers
BTW saying that you are reaaaaaaaally busy is your problem not ours. We all have our own issues/workloads and must manage them. Don't impose your timeframes on us.
- 10-18-2012, 07:30 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Re: generating random integers
public class project6 {
private static Scanner stdin;
public static void main(String[] args) {
stdin = new Scanner(System.in);
int number;
int freq0 = 0, freq1, freq2, freq3, freq4, freq5, freq6, freq7, freq8, freq9;
number = (int)(Math.random() * 99999);
switch(number){
case 1 : System.out.println("*" + freq0);
}
}
}
}
}
this is what i have and i do not know what to do i need the program to generate a random number and count the frequency of each digit then display asterisk of how many times the digit occurs.
- 10-18-2012, 10:10 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Re: generating random integers
now i have this
public class project6 {
private static Scanner stdin;
public static void main(String[] args) {
stdin = new Scanner(System.in);
int number, digit, min = 0;
int freq0 = 0, freq1 = 1, freq2 = 2, freq3, freq4, freq5, freq6, freq7, freq8, freq9;
//display random number.
number = (int)(Math.random() * 99999);
System.out.println(number);
//display digits of random number.
}
}
- 10-18-2012, 10:12 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Re: generating random integers
how do i display the digits of the number?
- 10-18-2012, 10:35 PM #7
Senior Member
- Join Date
- May 2012
- Posts
- 170
- Rep Power
- 2
- 10-19-2012, 09:56 AM #8
Member
- Join Date
- Sep 2012
- Location
- Guntur, India
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
Generating random numbers
By chinedum in forum New To JavaReplies: 9Last Post: 09-21-2011, 05:03 AM -
Math.random generating 0
By codeAJ in forum New To JavaReplies: 1Last Post: 03-25-2011, 08:17 AM -
generating random number between 0 and 1
By sara12345 in forum New To JavaReplies: 1Last Post: 04-17-2010, 07:54 PM -
Generating a random number
By oridov in forum New To JavaReplies: 2Last Post: 11-29-2008, 05:12 PM -
Random Integers
By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12-09-2007, 05:49 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks