whiplk

[CODE] - Read & Order file.

Oct 7th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Testes {
  5.     public static void main(String[] args) throws Exception {
  6.        
  7.         Scanner input = new Scanner(new File("file.txt"));
  8.        
  9.         int idx = 0;
  10.         while (input.hasNextInt()) {
  11.             idx ++;
  12.             input.nextInt();
  13.         }
  14.        
  15.         input.close();
  16.        
  17.         input = new Scanner(new File("file.txt"));
  18.        
  19.         int[] vec = new int[idx];
  20.         for(int i = 0; input.hasNextInt(); ++i) {
  21.             vec[i] = input.nextInt();
  22.         }
  23.        
  24.         for (int i = 0; i < vec.length; i++) {
  25.             int aux = -1;
  26.             for (int j = 0; j < vec.length - 1; j++) {
  27.                 if (vec[j] > vec[j + 1]) {
  28.                     aux = vec[j];
  29.                     vec[j] = vec[j + 1];
  30.                     vec[j + 1] = aux;
  31.                 }
  32.             }
  33.         }
  34.        
  35.         for (int i = 0; i < vec.length; ++i) {
  36.             System.out.println("" + vec[i]);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment