我在这里执行此循环时遇到问题。它第一次顺利运行,但在它第二次要求一个国家后,它不会让我投入。任何帮助?执行循环跳过代码
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(),因为这似乎是你的意思。 –