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

    • 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

    Random getRandom = new Random(12345);

    getRandom.nextInt(20);

    • 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javaio import javautil our main class public class Main our main method public static void mainString args throws Exception declaring a variable m int m Random rand new Random try block try cre... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!