第1个回答
2017-09-14
import java.util.*;
/**
* @author hardneedl
*/
public class ScoreInputDemo {
interface FilteredAction {
/**
* 判断是否接受
* @param t 输入的数值
* @return true
表示接受; false
表示拒绝
*/
boolean accept(T t);
/**
* 干活吧
* @param t 输入参数
*/
void perform(T t);
/**
* 取计算结果
* @return 结果
*/
R getResult();
}
public static void main(String... args) {
FilteredAction> filteredAction = new FilteredAction>() {
List scores = new ArrayList<>(50);
public boolean accept(Integer t) {
return t > -1 && t
}
public void perform(Integer t) {
if(accept(t)){
scores.add(t);
}
}
public List getResult() {
return new ArrayList<>(scores);
}
};
System.out.println("请输入分数(输入-1时,表示输入结束):");
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
while (i