473,405 Members | 2,187 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,405 software developers and data experts.

Math.random and Arrays

9
this what i got so far. i understand arrays and Math.random i think,but i need to use Math.random and arrays to make 100 random integers between 1 -9 what am i doing wrong? and what am i missing


import java.util.*;

import javax.swing.JOptionPane;
public class hw_7 {

public static void main(String[] args){
Scanner input=new Scanner(System.in);
int Random =input.nextInt();
int[] anArray;

anArray = new int[10];
int random =(( int)(Math.random()*10)+99);
anArray[0] = 0;
anArray[1] = 1;
anArray[2] = 2;
anArray[3] = 3;
anArray[4] = 4;
anArray[5] =5;
anArray[6] = 6;
anArray[7] = 7;
anArray[8] = 8;
anArray[9] = 9;
System.out.print(anArray);





}

}
Apr 10 '10 #1
4 9848
jkmyoung
2,057 Expert 2GB
anArray = new int[10];
Only holds 10 integers. You said you want 100.

int random =(( int)(Math.random()*10)+99);
This generates a random number from (99 - 109).

Example:
anArray[0] = ( int)(Math.random()*9);
Apr 12 '10 #2
jca613
9
public class hw_7{

public static void main(String[] args){
int[] anArray = new int[100];
for(int index =0; index <anArray.length; index++){
anArray[index] = (int) (Math.random()*10);
}
for(int element = 0; element < anArray.length; element++) {
System.out.println("anArray[" + element + "]\t" + anArray[element]);
}
}
}

that is what i got so far now. count the occurrences of the digits. my output should look something liek this

Digit:
0 1 2 3 4 5 6 7 8 9
Count:
8 13 8 12 6 12 9 10 10 12


but what can i ad to my code to make it look like that?
Apr 21 '10 #3
jkmyoung
2,057 Expert 2GB
How are you going to store those count numbers? Figure out a way to store the counts.

Then you can loop through your array, setting the storage accordingly.
Apr 21 '10 #4
jca613
9
i honestly i have no idea.my brain is like frying trying to figure this out. do i do something like make another loop array? and put char, then count digitis.
Apr 21 '10 #5

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

Similar topics

5
by: R. Russell Kinter | last post by:
Hi all, First of all I am fairly new to javascript. Most of my experience has been with its subset vrmlscript, so have mercy. The following script works in I.E. 5.5, but hangs up in Netscape 4.8...
4
by: Robert Scheer | last post by:
Hi. Reading about the Math.random method I saw that by default it generates between 0 and 1. To generate numbers between a greater range I can use these syntaxes: x = Math.random()/10 x =...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
3
by: Bart Vandewoestyne | last post by:
Simple question: does the Java standard specify what random number generator algorithm should be used for Math.random() ? If 'no', then can anybody tell me what PRNG is behind Sun's version of...
8
by: babyshuyi | last post by:
Hey there guys, I was wondering if anyone could be helpful enough to help me with this. I am very new to Java.I am trying to understand how to work and use a Math.random() in my assignment where I...
34
by: Johannes Baagoe | last post by:
About Math.random(), ECMA 262 just says "Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform...
2
by: Helmer | last post by:
i am in programming class trying to make an applet involving random placement of colored blocks, but an error is created when i try to run it saying "no method named "random" was found in type...
1
by: IanSD81 | last post by:
This may be a stupid question but how can you start Math.Random() to start generating numbers after a specific number. Say the number is 53 how do you call Math.random() so that it will not generate...
32
by: C. (http://symcbean.blogspot.com/) | last post by:
Hi all, I have an application which generates image graphs. These cache nicely at the client, however if the user submits more data, I'd like to force a reload of the image from the server. I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.