【发布时间】:2016-03-28 07:15:17
【问题描述】:
我正在获取用户输入并使用 while 循环来继续验证输入。 但是,无论我输入什么类型的输入应该是正确的,它都会不断返回错误并重复循环。
这是使用循环的代码部分:
String deletelName;
System.out.println("Type patient's last name to delete");
deletelName = cin.next();
Patient removePatient = new Patient (deletelName.toLowerCase(),null,null,null,null);
while (!bst.contains(removePatient)) {
System.out.println("Patient's last name does not exist. Type another last name : ");
deletelName = cin.next();
}
部分bst类:
public boolean contains(AnyType x)
{
return contains(x, root);
}
private boolean contains(AnyType x, BinaryNode<AnyType> t)
{
if (t == null)
return false;
int compareResult = x.compareTo(t.element);
if(compareResult < 0)
return contains(x, t.left);
else if (compareResult > 0)
return contains (x, t.right);
else
return true;
}
【问题讨论】:
-
什么是
bst?您需要提供比这更多的代码。
标签: java while-loop