Advertisement
nguyenvanquan7826

Array1

May 16th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.util.Arrays;
  7. import java.util.Scanner;
  8. class InitArray
  9. {
  10.     int [] Element = new int[100];
  11. }
  12. class IOArray extends InitArray
  13. {
  14.     void input_file() throws FileNotFoundException
  15.     {
  16.         FileInputStream fi = new FileInputStream("input.txt");
  17.         Scanner inp = new Scanner(fi,"UTF-8");
  18.         String temp = inp.nextLine(); //doc dong mang trong file
  19.         inp.close();
  20.        
  21.         String [] item = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
  22.         for(int i=0; i<item.length; i++) //doi kiem string sang int cua cac phan tu
  23.             Element[i] = Integer.parseInt(item[i]);
  24.         Element.length = item.length;
  25.     }
  26.     void output_file() throws IOException
  27.     {
  28.         FileOutputStream fo = new FileOutputStream("output.txt");
  29.         PrintWriter out = new PrintWriter(fo);
  30.         for (int i=0; i<Element.length; i++)
  31.             out.printf("%-5d",Element[i]);
  32.         out.close();
  33.     }
  34. }
  35.  
  36. class SortArray extends InitArray
  37. {
  38.     public void soft(IOArray A)
  39.     {
  40.         Arrays.sort(A.Element);
  41.     }
  42.     public void show(IOArray A)
  43.     {
  44.         for(int i=0; i<A.Element.length; i++)
  45.         {
  46.             System.out.print(A.Element[i]+" ");
  47.         }
  48.     }
  49. }
  50.  
  51. class Array
  52. {
  53.     public static void main(String[] args) throws IOException
  54.     {
  55.         IOArray Arr = new IOArray();
  56.         Arr.input_file();
  57.         Arr.output_file();
  58.         SortArray softarr = new SortArray();
  59.         softarr.soft(Arr);
  60.         softarr.show(Arr);
  61.         System.out.println("\nSucces ! Open file output.txt to view");
  62.     }
  63. }
  64. /*
  65. class SortArray extends IOArray
  66. {
  67.     SortArray Arr = new SortArray();
  68.     Arr
  69.     public void soft()
  70.     {
  71.         Arrays.sort(Element);
  72.     }
  73.    
  74.     public void show()
  75.     {
  76.         for(int i=0; i<n; i++)
  77.         {
  78.             System.out.print(Element[i]+" ");
  79.         }
  80.     }
  81. }
  82.  
  83. class Array
  84. {
  85.     public static void main(String[] args) throws IOException
  86.     {
  87.         //IOArray Arr = new IOArray();
  88.         SortArray Arr = new SortArray();
  89.         Arr.input_file();
  90.         Arr.soft();
  91.         Arr.show();
  92.         Arr.output_file();
  93.         System.out.println("Succes ! Open file output.txt to view");
  94.     }
  95. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement