gpt4 book ai didi

java - For 循环接受额外的数组成员

转载 作者:行者123 更新时间:2023-12-01 08:08:06 25 4
gpt4 key购买 nike

我正在运行一个 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();
}

编辑我意识到我不需要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;
}

患者管理类(class):

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();
}
}

这不是调用Patient.getOption();。有什么想法吗?

最佳答案

您正在调用 Patient.getNewPt 6 次。

在循环外一次,然后在循环内 5 次。

关于java - For 循环接受额外的数组成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19759212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com