逆序排序的使用练习 1 2 3 4 5 6 逆序成 6 5 4 3 2 1

来源:互联网 发布:呼和浩特软件招聘信息 编辑:程序博客网 时间:2024/06/11 01:39
<span style="font-size:18px;">//逆序排序的使用练习public class NiSuPaiLie {public static void main(String[] args) {// 记录程序开始的时间 long 类型 毫秒类型long a1 = System.currentTimeMillis();int[] array = { 88, 4, 6, 7, 8, 9 };// Arrays.sort(array);for (int temp : array)System.out.print(temp + "  ");System.out.println();fun(array);for (int temp : array)System.out.print(temp + "  ");System.out.println();// 换行// 基本数据类型作为方法的参数,传递的是数值;// 引用数据类型作为方法的的参数,传递的是地址;int a = 20;fun1(a);System.out.println(a);// 程序运行完需要多少毫秒long a2 = System.currentTimeMillis();System.out.println("***********");System.out.println((a2 - a1) + "毫秒");// 因为程序太小了 所以有时候为0}/** * 基本数据类型作为方法的参数,传递的是数值 *  * @param a */public static void fun1(int a) {a = a + 10;}/** * 数组元素逆序排序的方法 其中把数组作为参数(形参) *  * @param array */public static void fun(int[] array) {int temp;for (int i = 0; i < array.length / 2; i++) {temp = array[array.length - 1 - i];array[array.length - 1 - i] = array[i];array[i] = temp;}}}</span>

0 0
原创粉丝点击