java例程练习(一维数组)

public class Test {
	
	public static void main(String[] args) {
		
		int a[] = { 3, 9, 8}; //静态初始化
		
		Date days1 [] = {
				new Date(1, 4, 2004),
				new Date(2, 4, 2004),
				new Date(3, 4, 2004)
		};
		
		
		//动态初始化
		Date [] days2 = new Date[3];
		
		for (int i = 0; i < 3; i++) {
			days2[i] = new Date(2004, 5, i + 1);
			System.out.println(days2[i]);
		}
		
		
	}
	
}

class Date {
	int year;
	int month;
	int day;
	
	Date(int year, int month, int day) {
		this.year = year;
		this.month = month;
		this.day = day;
	}

	public String toString() {
		return "" + year + "-" + month + "-" + day;
	}
}

你可能感兴趣的:(java,Date,String,Class)