private void addMember() {
while (true) {
String mNum = readLine("Please enter a membership number: ");
if (mNum == null) break;
Integer mNumAsInteger = Integer.parseInt(mNum);
String mName = readLine("Please enter the member's name: ");
members.put(mNumAsInteger, mName);
}
}
private Map<Integer, String> members = new HashMap<Integer, String>();
代码的目的是不断添加成员,直到用户输入空白输入。
有没有办法将第一行更改为类似
Integer mNum = readInt("Please enter a membership number: ");
并以某种方式检测到空白输入?