一个int型有序数组,如何拿到最低的值和这个值一共存在多少个?
示例代码:
int min = 0;
int os = 1;
int[] element = {5,4,4,2,2};
for (int i : element) {
if (i == min) {
os++;
} else {
min = i;
os = 1;
}
}
System.out.println("min = " + min);
System.out.println("os = " + os);
代码运行结果: