1

我想创建一个编号列表,它在每行旁边显示索引号。我不太确定如何实现这一目标。

这是我创建列表的代码:

public void readFile(Scanner in)
{
    inputStudentID = null;
    inputMark = 0;

    try
    {
        File file = new File("Marks.txt");
        in = new Scanner(file);
    }
    catch (FileNotFoundException e)
    {
        System.out.println(e.getMessage());
        System.out.println("in " + System.getProperty("user.dir"));
        System.exit(1);
    }
    while (in.hasNextLine())
    {
        String studentRecord = in.nextLine();
        List<String> values = Arrays.asList(studentRecord.split(","));
        String inputStudentID = values.get(0);
        String sInputMark;
        sInputMark = values.get(1);
        int inputMark = Integer.parseInt(sInputMark);
        addStudent(inputStudentID, inputMark);
    }
    in.close();
}
4

0 回答 0