【发布时间】:2015-09-20 13:45:25
【问题描述】:
即使我输入的名字在数组中,这段代码总是说它不在列表中。这与我设置 searchValue 的值有关系吗?
String[] stuName = new String[MAX_ON_LIST];
int currentSize = 0;
for (int i = 0; i < stuName.length; i++) {
stuName[i] = JOptionPane.showInputDialog("Enter student name:");
}
String searchValue = JOptionPane.showInputDialog("Enter a name:");;
int position = 0;
boolean found = false;
while (position < stuName.length && !found) {
if (stuName[position] == searchValue) {
found = true;
}
else {
++position;
}
}
if (found) {
stuName[1] = stuName[currentSize - 1];
--currentSize;
JOptionPane.showMessageDialog(null, Arrays.toString(stuName));
}
else {
JOptionPane.showMessageDialog(null, "Name not on list");
JOptionPane.showMessageDialog(null, Arrays.toString(stuName));
}
【问题讨论】:
标签: java