Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.io.*; public class Practice_Assignment_8 { public static void main(String args) throws IOException { int randomNumber; int i; int total = 0; PrintWriter fileOutput =
import java.io.*; public class Practice_Assignment_8 { public static void main(String args) throws IOException { int randomNumber; int i; int total = 0; PrintWriter fileOutput = new PrintWriter("numbers.dat"); Random rand = new Random(); for (i = 1; i <= 20; i ) { randomNumber = rand.nextInt(100); fileOutput.println(randomNumber); } fileOutput.close(); Scanner fileInput = new Scanner(new File("numbers.dat")); System.out.println("The numbers in the file \"numbers.dat\": "); while (fileInput.hasNext()) { randomNumber = fileInput.nextInt(); System.out.printf(randomNumber " "); total = total randomNumber; } System.out.print(" The total of the numbers is: " total); fileInput.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started