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

本文介绍了一个简单的Java程序,演示如何实现数组元素的逆序排序。通过一个具体示例,展示了数组逆序排序的过程,并比较了基本数据类型与引用数据类型在方法调用时的不同行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值