• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with arrays  RSS feed

 
Shabba Ranks
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given a 50 element array called fifty and random numbers between 0 and 49, count the occurrences of each number by incrementing the corresponding element (i.e., if a 3 is generated, then element at index 3 is incremented by 1). you should use a for-loop to generate 235 random numbers. Output the results of the fifty array:
Random gen = new Random( );
int num;
//for-loop to generate 235 random numbers
num = gen.nextInt(50); //generates one random number from 0 to 49
//output fifty array

* I need help understanding how to do arrays. Can some one explain the steps in completing the code above?
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!