Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Arrays;
- import java.util.Scanner;
- class InitArray
- {
- int [] Element = new int[100];
- int n;
- }
- class IOArray extends InitArray
- {
- void input_file() throws FileNotFoundException
- {
- FileInputStream fi = new FileInputStream("input.txt");
- Scanner inp = new Scanner(fi,"UTF-8");
- String temp = inp.nextLine(); //doc dong mang trong file
- String item[] = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
- n = item.length;
- for(int i=0; i<n; i++) //doi kiem string sang int cua cac phan tu
- Element[i] = Integer.parseInt(item[i]);
- inp.close();
- }
- void output_file() throws IOException
- {
- FileOutputStream fo = new FileOutputStream("output.txt");
- PrintWriter out = new PrintWriter(fo);
- for (int i=0; i<n; i++)
- out.printf("%-5d",Element[i]);
- out.close();
- }
- }
- class SortArray extends IOArray
- {
- public void soft()
- {
- Arrays.sort(Element);
- }
- public void show()
- {
- for(int i=0; i<n; i++)
- {
- System.out.print(Element[i]+" ");
- }
- }
- }
- class Array
- {
- public static void main(String[] args) throws IOException
- {
- //IOArray Arr = new IOArray();
- SortArray Arr = new SortArray();
- Arr.input_file();
- Arr.soft();
- Arr.show();
- Arr.output_file();
- System.out.println("Succes ! Open file output.txt to view");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement