for循环接受额外的数组成员

Yve*_*omb 0 java arrays for-loop

我正在运行一个for循环,它接受6个病人,当它应该只接受5.我不知道为什么.

患者类:

public Patient(final String ptNo, final String ptName,
        final String procDate, final int procType, final String injury,
        final String drName) throws IOException
{
    Patient.ptNo = getPtNo();
    Patient.ptName = getPtName();
    Patient.procDate = getProcDate();
    Patient.procType = getProcType();
    Patient.injury = getPtNotes();
    Patient.drName = getDrName();
}
Run Code Online (Sandbox Code Playgroud)

编辑我意识到我不需要getNewPt

public static Patient getNewPt(String ptNo, String ptName,
        String procDate, int procType, String 
        injury, String drName) throws IOException
{
    Patient newPt = new Patient (ptNo,
            ptName, procDate, procType, injury, drName);

    return newPt;
}
Run Code Online (Sandbox Code Playgroud)

患者管理课程:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PatientManagementSystem
{
    static BufferedReader stdin = new BufferedReader(new InputStreamReader(
            System.in));

    public static void main(String[] args) throws IOException
    {

        Patient.getNewPt(null, null, null, 0, null, null);
        // creating an array of 5 patients
        Patient patients[] = new Patient[5];

        int i = 0;

        for (i = 0; i < 5; i++)
        {
            patients[i] = Patient.getNewPt(null, null, null, i, null, null);

        }
        Patient.getOption();
    }
}
Run Code Online (Sandbox Code Playgroud)

这不是来自召唤Patient.getOption();.有任何想法吗?

Dan*_*umb 6

你打了Patient.getNewPt六次电话.

一旦在循环外,然后循环内部5次.