Advertisement
nguyenvanquan7826

Array

May 16th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 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.Scanner;
  7. class InitArray
  8. {
  9.     int [] Element = new int[100];
  10.     int n;
  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.         String item[] = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
  20.         n = item.length;
  21.         for(int i=0; i<n; i++) //doi kiem string sang int cua cac phan tu
  22.             Element[i] = Integer.parseInt(item[i]);
  23.         inp.close();
  24.     }
  25.     void output_file() throws IOException
  26.     {
  27.         FileOutputStream fo = new FileOutputStream("output.txt");
  28.         PrintWriter out = new PrintWriter(fo);
  29.         for (int i=0; i<n; i++)
  30.             out.printf("%-5d",Element[i]);
  31.         out.close();
  32.     }
  33. }
  34.  
  35. class SortArray extends InitArray
  36. {
  37.     //em muốn lớp này kế thừa đẻ săp xếp mà không được
  38. }
  39.  
  40. class Array
  41. {
  42.     public static void main(String[] args) throws IOException
  43.     {
  44.         IOArray Arr = new IOArray();
  45.         Arr.input_file();
  46.         Arr.output_file();
  47.         System.out.println("Succes ! Open file output.txt to view");
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement