Question: Write a program to create a file named integerFile.txt if it does not exist. Write 100 integers created randomly into the file using text I/O.
Write a program to create a file named integerFile.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. The random integers should be in the range 0 to 100 (including 0 and 100). Integers should be separated by spaces in the file. Read the data back from the file and display the data in increasing order
This is what I have so far:
import java.io.File; import java.util.Scanner; import java.io.PrintWriter; public class integerFile { public static void main (String[] args) throws Exception{ Scanner input = new Scanner(System.in); File file = new File("integerFile.txt"); try (PrintWriter pw = new PrintWriter(new PrintWriter(file));) { for (int i = 0; i < 100; i++) { pw.print((int)(Math.random() * 100) + " "); } pw.close(); } while(input.hasNext()){ } } } Help finish in Java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
