Menu: Difference between revisions

516 bytes added ,  14 years ago
Added Java
(New task and Python solution)
 
(Added Java)
Line 9:
 
Note: This task is fashioned after the action of the [[http://www.softpanorama.org/Scripting/Shellorama/Control_structures/select_statements.shtml Bash select statement]].
=={{header|Java}}==
 
<lang java5>public static String select(List<String> list, String prompt){
if(list.size() == 0) return "";
Scanner sc = new Scanner(System.in);
String ret = null;
do{
for(int i=0;i<list.size();i++){
System.out.println(i + ": "+list.get(i));
}
System.out.print(prompt);
int index = sc.nextInt();
if(index >= 0 && index < list.size()){
ret = list.get(index);
}
}while(ret == null);
return ret;
}</lang>
=={{header|Python}}==
 
Anonymous user