东软学习小组成员:夜枫
入参:年份
返回:字符串
如:2019
返回:你现在是大一下学期
如:2018
返回:你现在是大二下学期

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
static String a(int year) {
String res = null;
int time_year;
int time_month;
Date time = new Date(); //2016 2017 2018 2019 2020
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyy-MM-dd");
res = simpleDateFormat.format(time);
time_year=Integer.parseInt(res.substring(0,4));
// time_year=2019;
// time_month=10;
time_month=Integer.parseInt(res.substring(5,7));

//处理时间超时
if(year>time_year){
res="时间太后了,你还没到那个时候入学";

}
if(year==time_year){//相同年,但是月份还不到9月
if(time_month<9){
res="你还不到入学时间,等九月份你就是大一啦";
}
else if(time_month>=9){
res="你现在是大一上学期";
}

}
//2020 3 2019 6
if(time_year>year){
int temp=time_year-year;//时差
if(temp<=3){
String []Class={"大一","大二","大三","大四"};
res="你现在是"+Class[temp-1];
if(time_month<9){
res+="下学期";
}else {
if(temp<3){//不是大四
res=Class[temp]+"上学期";
}else if(temp==3){//大四
res="上半年是大四下学期啦,现在已经你毕业几个月了";

}

}
}
else if(temp>3){//2020 2019 2018 2017 2016

int year1=temp-3;//毕业多少年
int momth1=time_month;//毕业多少月
if(time_month<6){
year1-=1;
momth1=time_month+12-6;

}
res="你已经毕业"+String.valueOf(year1)+"年"+String.valueOf(momth1)+"月了";
}

}

return res;
}

java源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// int year = sc.nextInt();
for(int i=2010;i<2022;i++){
String t=a(i);
System.out.println(i+"的结果:-->"+t);
}

//System.out.println(t);
}

static String a(int year) {
String res = null;
int time_year;
int time_month;
Date time = new Date(); //2016 2017 2018 2019 2020
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyy-MM-dd");
res = simpleDateFormat.format(time);
time_year=Integer.parseInt(res.substring(0,4));
// time_year=2019;
// time_month=10;
time_month=Integer.parseInt(res.substring(5,7));

//处理时间超时
if(year>time_year){
res="时间太后了,你还没到那个时候入学";

}
if(year==time_year){//相同年,但是月份还不到9月
if(time_month<9){
res="你还不到入学时间,等九月份你就是大一啦";
}
else if(time_month>=9){
res="你现在是大一上学期";
}

}
//2020 3 2019 6
if(time_year>year){
int temp=time_year-year;//时差
if(temp<=3){
String []Class={"大一","大二","大三","大四"};
res="你现在是"+Class[temp-1];
if(time_month<9){
res+="下学期";
}else {
if(temp<3){//不是大四
res=Class[temp]+"上学期";
}else if(temp==3){//大四
res="上半年是大四下学期啦,现在已经你毕业几个月了";

}

}
}
else if(temp>3){//2020 2019 2018 2017 2016

int year1=temp-3;//毕业多少年
int momth1=time_month;//毕业多少月
if(time_month<6){
year1-=1;
momth1=time_month+12-6;

}
res="你已经毕业"+String.valueOf(year1)+"年"+String.valueOf(momth1)+"月了";
}

}

return res;
}
}