java - 冒泡排序求最值
public class Bubble3 { public static void main(String[] args) { int[] arr; arr = new int[]{2,3,6,1}; Bubble3 Bu3 = new Bubble3(); Bu3.jiaohuan(arr); } void jiaohuan(int[] arr){ for(int i=0;i<arr.length-1;i++){ // < 求最小值 , >求最大值 if(arr[i]<arr[i+1]){ arr[i] = arr[i]^arr[i+1]; arr[i+1] = arr[i+1]^arr[i]; arr[i] = arr[i]^arr[i+1]; } } for(int item : arr){ System.out.println(item); } System.out.println("最值 : "+arr[arr.length-1]); } }