-4

宣言行を必要とする単純なプログラムを進行中です

read = new BufferedReader(new FileReader("marks.txt"));

行 = read.readLine();

クラス変数になります。どうすればいいですか?

これまでに書いたコードは次のとおりです。

import java.io.*;
import java.math.*;

public class WriteKong
{
    public static String line;
    public static BufferedReader read;
public static PrintWriter write;

    public static void main(String[] args) throws IOException
    {       
            read = new BufferedReader(new FileReader("marks.txt"));
            line = read.readLine();

        while(line != null)
        {
            System.out.println(line);
            read.readLine();
        }
    }

    public static void sort()
    {
    // THIS IS WHAT THE FUNCTION DOES:
    //  > check the fourth digit in the line
    //  > if there is no fourth digit then store the mark
    //  > if mark is less than 50 then write to "fail.txt"
    //  > if mark is 50 or greater then write to "pass.txt"


    }

}

編集:これらの変数をクラス変数として宣言したい。使用するすべてのメソッドで同じ変数を再定義するという苦痛を経験したくありません。

4

1 に答える 1

2

これらはコード内のクラス変数です。コードは指定された要件を満たしています。

ループがファイルからすべての行を読み取らない理由が混乱している場合は、新しく読み取った行を に割り当てていないためですline

于 2013-08-10T18:51:28.210 に答える