[java]代码库
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int year1 = scan.nextInt();
int month1 = scan.nextInt();
int day1 = scan.nextInt();
MyDate date1 = new MyDate(year1, month1, day1);
int year2 = scan.nextInt();
int month2 = scan.nextInt();
int day2 = scan.nextInt();
MyDate date2 = new MyDate(year2, month2, day2);
date1.print();
System.out.print(date1.compare(date2));
scan.close();
}
}
class MyDate {
private int year;
private int month;
private int day;
public MyDate(int Y, int M, int D) {
year = Y;
month = M;
day = D;
}
public int getYear() {
return year;
}
public int getMonth() {
return month;
}
public int getDay() {
return day;
}
int compare(MyDate d) {
if(this.year < d.getYear())
return -1;
else if(this.year > d.getYear())
return 1;
else
{
if(this.month < d.getMonth())
return -1;
else if(this.month > d.getMonth())
return 1;
else {
if(this.day < d.getDay())
return -1;
else if(this.day > d.getDay())
return 1;
else
return 0;
}
}
}
void print() {
System.out.print(month+"/"+day+"/"+year+" ");
}
}