int[] arr = new int[]{2,4,3,12,5,8,6,9,7}; //选择排序 for(int i=0;i<arr.length-1;i++){ for(int j=i+1;j<arr.length;j++){ if(arr[i]>arr[j]){ int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } } for(int a:arr){ System.out.print(a+"-"); } System.out.println(); //冒泡 for(int i=0;i<arr.length-1;i++){ for(int j=0;j<arr.length-i-1;j++){ if(arr[j]>arr[j+1]){ int t = arr[j]; arr[j] = arr[j+1]; arr[j+1] = t; } } } for(int a:arr){ System.out.print(a+"-"); } }
/** * 递归 * @author Administrator * */ public class Recursion { public static void main(String[] args) { System.out.println(recur(4)); } //1~n的阶乘 或者连加 public static int recur(int n){ if(n==1){ return n; }else{ return n*recur(n-1); // return n+recur(n-1); } } }