Advertisement
RazorBlade57

Lab 4

Apr 8th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1.  
  2. //Lab 4
  3.  
  4.  
  5.  
  6.  
  7.  
  8. import java.util.*;
  9. import java.io.*;
  10.  
  11. public class read{
  12.  
  13.     public static void main(String[] args) throws Exception{
  14.        
  15.         try {
  16.        
  17.         File nfile = new File("Excercise12_15");
  18.        
  19.         PrintWriter outdata = new PrintWriter( nfile );
  20.        
  21.         for (int i = 0; i< 100; i++) {
  22.            
  23.             int x = 0;
  24.            
  25.             x = (int) (Math.random()*1000);
  26.            
  27.             outdata.print(x + " ");
  28.            
  29.             if (i == 99) {
  30.                 outdata.close();
  31.             }
  32.            
  33.         }
  34.        
  35.        
  36.         Scanner nin = new Scanner( nfile );
  37.        
  38.         int x = 0;
  39.        
  40.         ArrayList<Integer> array = new ArrayList<Integer>();
  41.        
  42.         while(nin.hasNext()) {
  43.            
  44.             array.add(nin.nextInt());
  45.            
  46.                     }
  47.        
  48.         array.sort(null);
  49.         System.out.println(array);
  50.        
  51.         }catch (IOException exp) {
  52.             System.out.println("Unable To Write Data.");
  53.         }
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement