所以我的代码工作正常,但它并不漂亮,但它可以完成工作:)
现在我想编写一段代码,如果文本文件中有19个或更多数据,则会停止打印数据,然后显示一条消息,说明"输入无效"例如。
任何帮助将不胜感激。
<% food = %w(breakfast lunch deli contact) %>
<ul class="nav navbar-nav">
<% food.each do |meal| %>
<li><%= active_link_to meal.titleize, eval("#{meal}_path") %></li>
<% end %>
</ul>
答案 0 :(得分:1)
考虑到您的String
数组包含文件中的数据,您只需使用此数组的长度来确定它是否超出限制。例如:
String[] strings = br.readLine().split(",");
if(strings.length >= 19) // Check whether there is more data then you expected
{
System.out.println("Invalid input");
return; //Return from the main function, stop the program
}