daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. i want to make an array of integers with 20 elements. the array would fill random numbers. Use a foreach loop to print all integers in the array. The following code can be used to make a random number each time through the loop. Also, note that you will have 2 loops: 1 for loop to populate an array with random numbers and a second foreach to output each of the random values from the array.
  2.  
  3.  
  4.  
  5. Use this code to make a Random object called random. Put this code before the for loop.
  6.  
  7. Random random = new Random();
  8.  
  9. int randomNumber;
  10.  
  11.  
  12.  
  13. Use this code inside of your loop body to make a new random number each time through the loop:
  14.  
  15. randomNumber = random.Next(0, 100); // place this line in the loop
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top