package itws14; import java.util.Arrays; public class test { public static void main(String[] args) { int[] arr = {12, 24, 123, 563, 2345, 645, 23, 2}; //冒泡排序 for (int i = 0; i < arr.length; i++) { for (int j = i+1; j <arr.length; j++) { int temp; if (arr[j]<arr[i]) { temp=arr[j]; arr[j]=arr[i]; arr[i]=temp; } } } //增强for循环遍历 for (int i : arr) { System.out.println(i); } } //选出最大最小值 /* public static void main(String[] args) { int[] arr = {2, 5, 3, 8, 6, 45, 8}; int max = arr[0]; int min = arr[0]; for (int i = 1; i < arr.length; i++) { if (max < arr[i]) { max = arr[i]; } } for (int j = 1;
例题:增强for循环,冒泡排序,选出数组最大最小值 判断数组中是否有某个数字 随机生成十个不重复的数字
于 2022-11-14 20:46:13 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)