View difference between Paste ID: 4VgjfhmU and pa6CaB28
SHOW: | | - or go back to the newest paste.
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-
    int [] Element = new int[100];
9+
10-
    int n;
10+
	int [] Element = new int[100];
11
	int n;
12
}
13
class IOArray extends InitArray
14-
    void input_file() throws FileNotFoundException
14+
15-
    {
15+
	void input_file() throws FileNotFoundException
16-
        FileInputStream fi = new FileInputStream("input.txt");
16+
	{
17-
        Scanner inp = new Scanner(fi,"UTF-8");
17+
		FileInputStream fi = new FileInputStream("input.txt");
18-
        String temp = inp.nextLine(); //doc dong mang trong file
18+
		Scanner inp = new Scanner(fi,"UTF-8");
19-
        String item[] = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
19+
		String temp = inp.nextLine(); //doc dong mang trong file
20-
        n = item.length;
20+
		String item[] = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
21-
        for(int i=0; i<n; i++) //doi kiem string sang int cua cac phan tu
21+
		n = item.length;
22-
            Element[i] = Integer.parseInt(item[i]);
22+
		for(int i=0; i<n; i++) //doi kiem string sang int cua cac phan tu
23-
        inp.close();
23+
			Element[i] = Integer.parseInt(item[i]); 
24-
    }
24+
		inp.close();
25-
    void output_file() throws IOException
25+
	}
26-
    {
26+
	void output_file() throws IOException
27-
        FileOutputStream fo = new FileOutputStream("output.txt");
27+
	{
28-
        PrintWriter out = new PrintWriter(fo);
28+
		FileOutputStream fo = new FileOutputStream("output.txt");
29-
        for (int i=0; i<n; i++)
29+
		PrintWriter out = new PrintWriter(fo);
30-
            out.printf("%-5d",Element[i]);
30+
		for (int i=0; i<n; i++)
31-
        out.close();
31+
			out.printf("%-5d",Element[i]);
32-
    }
32+
		out.close();
33
	}
34
}
35-
class SortArray extends InitArray
35+
36
class SortArray extends IOArray
37-
    //em muốn lớp này kế thừa đẻ săp xếp mà không được
37+
38
	public void soft()
39
	{
40
		Arrays.sort(Element);
41
	}
42-
    public static void main(String[] args) throws IOException
42+
	
43-
    {
43+
	public void show()
44-
        IOArray Arr = new IOArray();
44+
	{
45-
        Arr.input_file();
45+
		for(int i=0; i<n; i++)
46-
        Arr.output_file();
46+
		{
47-
        System.out.println("Succes ! Open file output.txt to view");
47+
			System.out.print(Element[i]+" ");
48-
    }
48+
		}
49
	}
50
}
51
52
class Array
53
{
54
	public static void main(String[] args) throws IOException
55
	{
56
		//IOArray Arr = new IOArray();
57
		SortArray Arr = new SortArray();
58
		Arr.input_file();
59
		Arr.soft();
60
		Arr.show();
61
		Arr.output_file();
62
		System.out.println("Succes ! Open file output.txt to view");
63
	}
64
}