[java]代码库
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int y1 = scan.nextInt();
int m1 = scan.nextInt();
int d1 = scan.nextInt();
MyDate p1 = new MyDate(y1,m1,d1);
int y2 = scan.nextInt();
int m2 = scan.nextInt();
int d2 = scan.nextInt();
MyDate p2 = new MyDate(y2,m2,d2);
p1.print();
p1.compare(p2);
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;}
public void setYear(int y) { year = y; }
public void setMonth(int m) { month = m ;}
public void setDay(int d) { day = d; }
public void print(){
System.out.print(month + "/"+day+"/"+year+ " ");
}
public void compare(MyDate d)
{
if(this.year < d.getYear())
System.out.print("-1");
else if( this.year > d.getYear())
System.out.print("1");
else if (this.year == d.getYear())
{
if(this.month < d.getMonth())
System.out.print("-1");
else if( this.month > d.getMonth())
System.out.print("1");
else if (this.month == d.getMonth())
{
if(this.day< d.getDay())
System.out.print("-1");
else if( this.day > d.getDay())
System.out.print("1");
else if(this.day == d.getDay())
System.out.print("0");
}
}
}
}