package com. wdzl. homework;
import java. util. Calendar;
import java. util. Scanner;
public class TestCalendar {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
System. out. println ( "请输入年份:" ) ;
int year = sc. nextInt ( ) ;
System. out. println ( "请输入月份:" ) ;
int month = sc. nextInt ( ) ;
System. out. println ( "请输入日期:" ) ;
int date = sc. nextInt ( ) ;
Calendar cal = Calendar. getInstance ( ) ;
cal. set ( year, month- 1 , 1 ) ;
int week = cal. get ( Calendar. DAY_OF_WEEK) ;
int days = cal. getActualMaximum ( Calendar. DAY_OF_MONTH) ;
String header = "日一二三四五六" ;
for ( int i = 0 ; i < header. length ( ) ; i++ ) {
System. out. print ( header. charAt ( i) + "\t" ) ;
}
System. out. println ( ) ;
for ( int i = 0 ; i < week- 1 ; i++ ) {
System. out. print ( "\t" ) ;
}
for ( int i = 1 ; i <= days; i++ ) {
if ( i== date) {
System. out. print ( "[" + i+ "]\t" ) ;
} else {
System. out. print ( i+ "\t" ) ;
}
if ( ( i+ week- 1 ) % 7 == 0 ) {
System. out. println ( ) ;
}
}
}
}
package com. wdzl. demo04;
import java. util. Calendar;
import java. util. Date;
public class TestCalendar {
public static void main ( String[ ] args) {
Calendar cal = Calendar. getInstance ( ) ;
int year = cal. get ( Calendar. YEAR) ;
int month = cal. get ( Calendar. MONTH) + 1 ;
int date = cal. get ( Calendar. DATE) ;
int dayOfYear = cal. get ( Calendar. DAY_OF_YEAR) ;
System. out. println ( "现在是" + year + "年" + month + "月" + date + "日,本年中的第" + dayOfYear + "天" ) ;
int a = cal. getActualMaximum ( Calendar. DAY_OF_MONTH) ;
System. out. println ( a) ;
cal. set ( Calendar. MONTH, 1 ) ;
System. out. println ( Calendar. MONTH) ;
a = cal. getActualMaximum ( Calendar. DAY_OF_MONTH) ;
System. out. println ( a) ;
System. out. println ( cal. getMinimalDaysInFirstWeek ( ) ) ;
Date d = cal. getTime ( ) ;
cal. setTime ( d) ;
}
}
日期
package com. wdzl. demo04;
import java. util. Date;
public class TestDate {
public static void main ( String[ ] args) {
Date date = new Date ( ) ;
System. out. println ( date) ;
System. out. println ( System. currentTimeMillis ( ) ) ;
Date date1 = new Date ( 9999898989888 L) ;
System. out. println ( date1. toLocaleString ( ) ) ;
System. out. println ( date1. getTime ( ) ) ;
System. out. println ( date1. after ( date) ) ;
System. out. println ( date1. before ( date) ) ;
Object obj = new Object ( ) ;
System. out. println ( obj) ;
System. out. println ( obj. toString ( ) ) ;
}
}
枚举类型
package zuoye;
import java. util. Scanner;
public class Test1 {
public static void main ( String[ ] args) {
Test1 test1 = new Test1 ( ) ;
Scanner input = new Scanner ( System. in) ;
System. out. println ( "请输入星期的天数:" ) ;
System. out. println ( "MON TUES WED THUR FRI SAT SUN" ) ;
String week = input. next ( ) ;
String weeks = week. toUpperCase ( ) ;
switch ( EnumWeek. valueOf ( weeks) ) {
case MON:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case TUES:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case WED:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case FRI:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case SAT:
System. out. println ( "星期天,好嗨哟" ) ;
break ;
case SUN:
System. out. println ( "星期天,好嗨哟" ) ;
break ;
default :
System. out. println ( "不好意思,你输入有误!" ) ;
break ;
}
input. close ( ) ;
}
public void display ( EnumWeek enumweek) {
switch ( enumweek) {
case MON:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case TUES:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case WED:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case FRI:
System. out. println ( "工作日,努力写代码!" ) ;
break ;
case SAT:
System. out. println ( "星期天,好嗨哟" ) ;
break ;
case SUN:
System. out. println ( "星期天,好嗨哟" ) ;
break ;
default :
System. out. println ( "不好意思,你输入有误!" ) ;
break ;
}
}
}
package com. wdzl. demo04;
public enum WeekEnum {
MON, TUS, WED, THU, FRI, SAT, SUN ( "" ) , ssss;
private WeekEnum ( ) { }
WeekEnum ( String ss) {
this . name = ss;
}
int age;
String name;
public void test ( ) { }
}
class Color {
public static final Color RED = new Color ( ) ;
public static final Color BLUE = new Color ( ) ;
public static final Color COLOR = new Color ( ) ;
}