java 利用一个一维数组,查找出该数组中的最大值和最小值

来源:百度知道 编辑:UC知道 时间:2024/05/27 02:10:50

package test;
public class Test {
public static void main(String[] args) {
int[] nums = { 2, 1, 4, 100, 88, 66, 123, 5, 74, 69 };
for (int i = 0; i <= nums.length - 1; i++) {
for (int j = i + 1; j <= nums.length - 1; j++) {
if (nums[i] > nums[j]) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
System.out.println("最小值为:" + nums[0] + " , 最大值为:"
+ nums[nums.length - 1]);
}
}

arrays.sort(arrys_name);排序后不是就有了吗.