标签:str 个数 ati 排序 public 第一个 最大数 使用 length
int[] nums = { 23, 12, 15, 9 }; for (int i = 0; i < nums.length; i++) { int index = i; for (int j = i + 1; j < nums.length; j++) { if (nums[i] > nums[j]) { index = j; } } System.out.println("第" + (i + 1) + "次排序前:"); System.out.println(Arrays.toString(nums)); int temp = nums[i]; nums[i] = nums[index]; nums[index] = temp; System.out.println("第" + (i + 1) + "次排序后:"); System.out.println(Arrays.toString(nums)); }
1 int[] nums = { 23, 12, 15, 9 }; 2 for (int i = 0; i < nums.length; i++) { 3 System.out.print("第" + (i + 1) + "次排序前:"); 4 System.out.println(Arrays.toString(nums)); 5 6 for (int j = 0; j < nums.length - i - 1; j++) { 7 if (nums[j] < nums[j + 1]) { 8 int temp = nums[j]; 9 nums[j] = nums[j + 1]; 10 nums[j + 1] = temp; 11 } 12 } 13 14 System.out.print("第" + (i + 1) + "次排序后:"); 15 System.out.println(Arrays.toString(nums)); 16 }
1 public static void printChengfabiao(int i) { 2 for (int a = 1; a <= i; a++) { 3 for (int b = 1; b <= a; b++) { 4 System.out.print(b + " * " + a + " = " + b * a + "\t"); 5 } 6 System.out.println(); 7 } 8 }
1 int[][] nums = new int[8][]; 2 for (int i = 0; i <= nums.length - 1; i++) { // 控制轮数 3 nums[i] = new int[i + 1]; // 开辟空间地址,循环给每个数组赋值,数组长度不固定 4 for (int j = 0; j <= i; j++) { 5 if (i == 0 || j == 0 || j == i) { 6 nums[i][j] = 1; 7 } else { 8 nums[i][j] = nums[i - 1][j - 1] + nums[i - 1][j]; 9 } 10 System.out.print(nums[i][j] + "\t"); 11 } 12 System.out.println(); 13 }
标签:str 个数 ati 排序 public 第一个 最大数 使用 length
原文地址:http://www.cnblogs.com/sunnytest/p/6639359.html