# storing a set of integers in an array

Khair Bahir

Greenhorn

Posts: 14

posted 4 years ago

Hello,

I'm trying to generate 50 random integers between 0 and 10 using a 'for' construct and the 'Math.random()' method. I know how to do this, but I don't know how to store all these integers in an array (one dimension). I really only know how to store integers by manually inputting them into the array. I haven't made much progress and could use some help.

This was my attempt (it doesn't work):

Thanks.

I'm trying to generate 50 random integers between 0 and 10 using a 'for' construct and the 'Math.random()' method. I know how to do this, but I don't know how to store all these integers in an array (one dimension). I really only know how to store integers by manually inputting them into the array. I haven't made much progress and could use some help.

This was my attempt (it doesn't work):

Thanks.

Abhinav Kumar Mishra

Greenhorn

Posts: 6

posted 4 years ago

hi

In the above code double value returned by random() function is converted into int before multiplication with 11.So we have to put the statement as

array[j]=(int)(Math.random()*11);

- 1

kae cee wrote:Hello,

I'm trying to generate 50 random integers between 0 and 10 using a 'for' construct and the 'Math.random()' method. I know how to do this, but I don't know how to store all these integers in an array (one dimension). I really only know how to store integers by manually inputting them into the array. I haven't made much progress and could use some help.

This was my attempt (it doesn't work):

Thanks.

hi

In the above code double value returned by random() function is converted into int before multiplication with 11.So we have to put the statement as

array[j]=(int)(Math.random()*11);

Matthew Brown

Bartender

Posts: 4565

8

Khair Bahir

Greenhorn

Posts: 14