首页下载资源行业研究23552679郭磊.zip

ZIP23552679郭磊.zip

wzy0503228.25KB需要积分:1

资源文件列表:

23552679郭磊.zip 大约有19个文件
  1. 23552679郭磊/selection/
  2. 23552679郭磊/selection/.idea/
  3. 23552679郭磊/selection/.idea/encodings.xml 205B
  4. 23552679郭磊/selection/.idea/misc.xml 276B
  5. 23552679郭磊/selection/.idea/modules.xml 265B
  6. 23552679郭磊/selection/.idea/workspace.xml 14.62KB
  7. 23552679郭磊/selection/out/
  8. 23552679郭磊/selection/out/production/
  9. 23552679郭磊/selection/out/production/selection/
  10. 23552679郭磊/selection/out/production/selection/cn/
  11. 23552679郭磊/selection/out/production/selection/cn/edu/
  12. 23552679郭磊/selection/out/production/selection/cn/edu/aynu/
  13. 23552679郭磊/selection/out/production/selection/cn/edu/aynu/SelectionSort.class 1.74KB
  14. 23552679郭磊/selection/selection.iml 433B
  15. 23552679郭磊/selection/src/
  16. 23552679郭磊/selection/src/cn/
  17. 23552679郭磊/selection/src/cn/edu/
  18. 23552679郭磊/selection/src/cn/edu/aynu/
  19. 23552679郭磊/selection/src/cn/edu/aynu/SelectionSort.java 1.8KB

资源介绍:

23552679郭磊.zip
package cn.edu.aynu; import java.util.Scanner; /** * company: www.abc.com * Author: Administrator * Create Data: 2024/9/11 0011 */ public class SelectionSort { public static void main(String[] args) { // 1 定义一个整型数组 int[] arr = new int[5]; // 2 通过键盘让用户随机输入5个整数,并赋值给数组 System.out.println("请输入5个整数:"); arrayInput(arr); // 3 输出原始数组 -- 排序前 System.out.println("排序前:"); printArray(arr); // 4 选择法排序 selectionSort(arr); // 5 输出排序结果 -- 排序后 System.out.println("排序后:"); printArray(arr); } // 定义一个为数组赋值的方法 private static void arrayInput(int[] arr) { Scanner sc = new Scanner(System.in); for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); } } // 定义一个选择法排序(由小到到排序)的方法 private static void selectionSort(int[] arr) { for (int i = 0; i < arr.length; i++) { int index = i; // 在一轮中查找最小数的下标 for (int j = i + 1; j < arr.length; j++) { if (arr[index] > arr[j]) { index = j; } } // 交换 if (index != i) { int tmp = arr[index]; arr[index] = arr[i]; arr[i] = tmp; } } } // 定义一个输出数组的方法 private static void printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { System.out.println("arr[" + i + "] = " + arr[i]); } } }
100+评论
captcha