Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import java.io.*;
- import java.util.Random;
- import java.util.Scanner;
- public class Program_5_2
- {
- //ITP_120 - 002N; LEE Program_5_2
- public static void main (String[] args)
- throws IOException
- {
- String fileName;
- int sum = 0;
- int upperRangeLimit = 100;
- int userRandomNumber;
- Random randomNumbers = new Random(100);
- boolean done = false;
- int x = 1;
- int q;
- while (!done)
- {
- fileName = JOptionPane.showInputDialog("Enter a file name or done to exit: ");
- if (!(fileName.equals("done")))
- {
- fileName = "fileName" + "_" + x++;
- Scanner keyboard = new Scanner(System.in);
- upperRangeLimit = Integer.parseInt(JOptionPane.showInputDialog("Enter the upper range limit:\\nMaximum range is 100"));
- //upperRangeLimit = keyboard.nextInt();
- userRandomNumber = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of random numbers you want to generate: "));
- //userRandomNumber = keyboard.nextInt();
- q = randomNumbers.nextInt(upperRangeLimit);
- //Random randomNumbers = new Random(upperRangeLimit);
- //upperRangeLimit = JOptionPane.showInputDialog("Enter the upper range limit:\n Maximum range is 100");
- //userRandomNumber = JOptionPane.showInputDialog("Enter the number of random numbers you want to generate: ");
- //creating the file
- File file = new File(fileName);
- //writing the random number to the new file
- PrintWriter outputFile = new PrintWriter(fileName);
- for (int n = 1; n < upperRangeLimit; n++)
- {
- sum = sum + q;
- outputFile.println(sum);
- }
- outputFile.close();
- Scanner inputFile = new Scanner(file);
- //while (inputFile.hasNext())
- //{
- // sum = inputFile + inputFile.nextInt();
- //}
- System.out.println(sum);
- inputFile.close();
- }
- else
- done = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement