【发布时间】:2018-01-20 22:03:54
【问题描述】:
我被要求提示用户输入字符串数据,然后根据包含用户应输入的值的数据数组验证用户输入,并提示用户该字符串无效。
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
//List of values the user suppose to enter
String[] list = {"Monday","Thusday", "Wednesday", "Thusday",
"Friday", "Saturday", "Sunday"}
System.out.println("Enter a day:"\n Eg: Monday or Thursday")
String day = keyboard.next();
/**
What should I write so that I can validate the user input against an
string array of days? And prompt the user again if his input is not
a day.
*/
}
【问题讨论】:
-
我们是一个问答网站,而不是雇佣编码员的服务。请将您的问题缩小到本网站主题的特定编码问题。请参阅:Why is "Can someone help me?" not an actual question? 和 How to ask a good question when I'm not sure what I'm looking for?
-
(a) 在发布之前始终搜索 Stack Overflow。您可以假设已经提出并回答了诸如此类的基本问题。 (b) 顺便看看
DayOfWeek枚举。
标签: java arrays string arraylist