For循环接受一个额外的数组成员 [英] For loop accepting an extra array member
本文介绍了For循环接受一个额外的数组成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行一个for循环,它接受6例,当它应该只接受我真的不知道为什么。
I'm running a for loop, and it is accepting 6 patients, when it should only be accepting 5. I don't know why.
Patient类:
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;
}
病人管理类:
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倍。
Once outside the loop and then 5 times inside the loop.
这篇关于For循环接受一个额外的数组成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文