我在這裏執行此循環時遇到問題。它第一次順利運行,但在它第二次要求一個國家後,它不會讓我投入。任何幫助?執行循環跳過代碼
import java.util.*;
public class UseList
{
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in);
ListInterface<String> list = new ArraySortedList<String>();
String country, flag;
char flagCharred;
do
{
System.out.print("Enter a country you've visited: ");
country = userInput.nextLine();
list.add(country);
System.out.print("\n" +list);
System.out.print("\nAdd another country?: Y/N ");
flag = userInput.next();
flagCharred = flag.charAt(0);
}
while (flagCharred == 'y' || flagCharred == 'Y');
}
}
下()只讀取一個字,而不是整個線。嘗試使用nextLine(),因爲這似乎是你的意思。 –