📄 program10_2.java
字号:
import java.text.*; // needed for formatting
public class Date
{
// class variable declaration section
private int month;
private int day;
private int year;
// class method definition section
public Date(int mm, int dd, int yyyy) // constructor
{
month = mm;
day = dd;
year = yyyy;
}
public void setEqual(Date newdate)
{
day = newdate.day; // assign the day
month = newdate.month; // assign the month
year = newdate.year; // assign the year
}
public void showdate()
{
DecimalFormat df = new DecimalFormat("00");
System.out.print(df.format(month)
+ '/' + df.format(day) + '/'
+ df.format(year % 100));
}
public static void main(String[] args)
{
Date a = new Date(04,01,1999); // create two Date objects
Date b = new Date(12,18,2001);
System.out.print("\nThe date stored in a is originally ");
a.showdate(); // display the original date
a.setEqual(b); // assign b's value to a
System.out.print("\nAfter assignment the date stored in a is ");
a.showdate(); // display a's values
System.out.println();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -