public ListInteger listType= new ArrayList;判断集合中的数据是否大于180或者小于-180 判断是否80以上的数据大于180或者小于180是的话返回false否则返回为true 给出具体代码
以下是给出的具体代码:
public boolean checkData(List<Integer> listType) {
int count = 0; // 记录大于180或小于-180的数据个数
for (int num : listType) {
if (num > 180 || num < -180) {
count++;
}
}
double percentage = (double) count / listType.size(); // 计算大于180或小于-180的数据所占比例
return percentage < 0.8; // 判断是否80%以上的数据大于180或小于180
}
可以通过调用checkData方法,传入要判断的集合listType,返回一个布尔值,true表示集合中的数据符合要求,false表示集合中的数据不符合要求。
原文地址: http://www.cveoy.top/t/topic/iYq7 著作权归作者所有。请勿转载和采集!