Make a loop that will write 5 random integers between value 0 and 20 to a new
Fantastic news! We've Found the answer you've been seeking!
Question:
- Make a loop that will write 5 random integers between value 0 and 20 to a new file called First
- Read the file First and append to the file 5 additional values that equal the current value read plus an additional random number between 0 and 20
- Read the file First and print out the 10 values on a single line
- Calculate the total of the values and print it out
- You will need java.util.*; and java.io.*; to allow the functions
- Use the following to generate the Random numbers
- Hint - break into pieces -
- first write loop to generate 5 random numbers - check file to be sure there
- Next add loop to read in 5 values and print them to be sure you are reading them in
- Next get rid of print and generate new integer that is current plus new random and append to file -- open file to see if there
- VERY IMPORTANT - PUT IN COMMAND readData.nextLine(); where readData is for Scanner -- need to make this before you do last loop to add and print the numbers -- it resets and cleans out buffer
- Write last loop to print each integer and also sum them to print sum
- HINT: the first 5 numbers of the 10 numbers you print are 11 0 1 8 15 and the total should be 101
Random getRandom = new Random(12345);
getRandom.nextInt(20);
Related Book For
Cambridge International AS & A Level Mathematics Probability & Statistics 1 Coursebook
ISBN: 9781108407304
1st Edition
Authors: Dean Chalmers, Julian Gilbey
Posted Date: