3qwee

Writing To a File // The "DiceData" class. // Simulate the throw of two dice 300 times // and store the generated data in file "dice". import java.io.*; public class DiceData { static public void main (String args []) throws IOException { int die1, die2, roll; PrintWriter output; output = new PrintWriter (new FileWriter ("c:/junk/dice.txt")); for (int count = 1 ; count <= 300 ; count++) { die1 = (int) (Math.random () * 6) + 1; die2 = (int) (Math.random () * 6) + 1; roll = die1 + die2; output.println (roll); } output.close (); //Note:To avoid losing information, be sure to close your files. This //releases any data temporarily held by DOS in memory. System.out.println ("Simulated data of 300 throws now in file 'dice'"); } // main method } /* DiceData class */ File Exercises 1) Write a program will read in strings and store them to a file (c:junkstrings.txt) one per line until the word “stop” is entered. The program will then read the file, output the strings, and output the number of strings stored in the file. 2) Write a program that will accept 5 strings and write them to a file named c:junkfile1.txt. The program will then accept another 5 strings and write them to a file called c:junkfile2.txt. files. A comparison between the strings contained within the two files will be preformed to see if any of the strings are the same.

Essay Information


Words: 907
Pages: 3.6
Rating: None

All Papers Are For Research And Reference Purposes Only. You must cite our web site as your source.