第05章 数组 09 练习7
2012-08-19 22:53
204 查看
鱼欲遇雨:每日都学习一点,持之以恒,天道酬勤!不能用电脑时,提前补上!(2012.9.6)
数组作为返回值内存分析
数组作为返回值内存分析
public class TestDateSort { public static void main(String args[]) { Date[] days = new Date[5]; days[0] = new Date(2006, 5, 4); days[1] = new Date(2006, 7, 4); days[2] = new Date(2005, 5, 4); days[3] = new Date(2004, 5, 9); days[4] = new Date(2004, 5, 4); BubbleSort(days); for(int i = 0; i<days.length; i++) { System.out.println(days[i]); } } public static Date[] BubbleSort(Date[] a) { int len = a.length; for(int i = len-1; i>=1; i--) { for(int j = 0; j<i-1; j++) { if(a[j].compare(a[j+1]) > 0) { Date temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } return a; } } /* public class Test { public static void main(String args[]) { Date[] days = new Date[10]; Date day = new Date(2004, 4, 6); } } */ class Date { int day,month,year; Date(int y, int m, int d) { this.year = y; this.month = m; this.day = d; } public int compare(Date date) { return year > date.year ? 1 : year < date.year ? -1 : month > date.month ? 1 : month < date.month ? -1 : day > date.day ? 1 : day < date.day ? -1 : 0; } public String toString() { return "Year: Month: Day:" + year + ":" + month + ":" + day; } }
相关文章推荐
- 第05章 数组 14 练习 12
- 15-09-常用对象API(String类-练习1-字符串数组排序)
- 第05章 数组 10 练习8
- 第05章 数组 11 练习9
- 第05章 数组 12 练习 10
- 第05章 数组 07 练习5
- 数据结构练习(09)排序数组中和为给定值的两个数字
- 第05章 数组 08 练习6
- 第05章 数组 03 练习1
- 第05章 数组 04 练习2
- 第05章 数组 05 练习3
- 第05章 数组 06 练习4
- 第05章 数组 13 练习 11
- 4-循环练习_数组
- java09数组的使用
- 数组的练习-----比赛求取平均分
- Java基本功练习十(多维数组强化二【悬挂的四子棋】)
- Codevs-4919 线段树练习4(区间加上一个值并求摸个区间整除k的数的个数,线段树+数组维护)
- 面向对象程序设计上机练习八(对象数组)
- [PowerShell教程][09]PowerShell中的数组使用