[ジャワ] ファイルからの配列を入力します。, Javaでソートされ、エクスポートされたファイル – ファイルからインポートアレイ, Javaでのソートおよびエクスポートファイル
– 作る 1 クラスの配列の初期化 (クラスInitArray)
– 作る 1 クラスの初期化ファイル配列レガシーのインポート、エクスポートクラス・アレイ (クラスIOArrayはInitArrayを拡張します)
– 作る 1 クラスクラスは、ソートされた配列の配列の初期化を継承します (クラスSortArrayはInitArrayを拡張します)
– クラス・アレイ (配列) 主な機能が含まれています() 実行可能プログラム
ここでは、コードです:
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;
}
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
inp.close();
String [] item = temp.split(" "); //tach chuoi thanh cac phan tu chuoi
Element = new int[item.length];
for(int i=0; i<item.length; i++) //doi kiem string sang int cua cac phan tu
Element[i] = Integer.parseInt(item[i]);
}
void output_file() throws IOException
{
FileOutputStream fo = new FileOutputStream("output.txt");
PrintWriter out = new PrintWriter(fo);
for (int i=0; i<Element.length; i++)
out.printf("%-5d",Element[i]);
out.close();
}
}
class SortArray extends InitArray
{
public void sort(IOArray A) //phuong thuc sap xep
{
Arrays.sort(A.Element);
}
}
class Array
{
public static void main(String[] args) throws IOException
{
IOArray Arr = new IOArray();
Arr.input_file(); //nhap tu file
SortArray SArr = new SortArray();
SArr.sort(Arr); //sap xep
Arr.output_file(); //xuat ra file
System.out.println("nSucces ! Open file output.txt to view");
}
}



人々は、クラスのクラスSortArray InitArrayを拡張する方法を私に尋ねます?
ああ私は本当に唯一の配列を使用することができます, 継承する必要もありません.
そして、私は事実を言っています :で
DKのためのALO町XIN顔MK MKのホイアンの味
あなたは経由で私と一緒にチャット何: fb.com/nguyenvanquan7826