所以这应该继续循环,直到用户点击“ENTER”或数组被填充。但是在输入数组中的第一个元素后,它会退出循环。
do
{
System.out.print("Enter name (or <ENTER> if done): ");
names[index] = kb.nextLine();
if(! (names[index].equals("")))
{
System.out.print("Enter phone number: ");
phone[index] = kb.nextLine();
System.out.print("Enter email address: ");
email[index] = kb.nextLine();
index++;
break;
}
} while ( ! (names[index - 1].equals("")) && index < SIZE);
已更正
do
{
System.out.print("Enter name (or <ENTER> if done): ");
names[index] = kb.nextLine();
if(! (names[index].equals("")))
{
System.out.print("Enter phone number: ");
phone[index] = kb.nextLine();
System.out.print("Enter email address: ");
email[index] = kb.nextLine();
}
index++;
} while ( ! (names[index - 1].equals("")) && index < SIZE);