package com.itemuch.cloud.test; import java.io.Serializable;import java.util.Date;import java.util.HashMap;import java.util.Map; public class javaBasical{ public static void main(String arsg[]){ int[] unSortNums = new int[]{ 1,3,4,5,2,9}; getSortResult(unSortNums); System.out.println("new Begin"); getTime(); } /** * @result 获取当前时间 */ private static void getTime() { Date time = new Date(); System.out.println(time); } /** * * @param nums * @result 获取冒泡排序结果 */ public static void getSortResult(int[] nums){ for(int i = 0;i < nums.length - 1; i++){////外层循环控制排序趟数 for(int j = 0 ;j <= nums.length -2 -i; j++){////内层循环控制每一趟排序多少次 if(nums[j] > nums[j+1]){ int temp = nums[j]; nums[j] = nums[j+1]; nums[j+1] = temp; } } } System.out.println("sortResultList:"); for (int num:nums) { System.out.print(" "+num+" "); } System.out.println(); }}
运行结果
sortResultList:
1 2 3 4 5 9
new Begin
Sun Dec 02 18:09:44 CST 2018
原文地址:https://www.cnblogs.com/zzzzw/p/10054405.html
时间: 2024-10-10 06:26:59