program10_5.java
来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 37 行
JAVA
37 行
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
{
this.month = mm;
this.day = dd;
this.year = yyyy;
}
public void showdate()
{
DecimalFormat df = new DecimalFormat("00");
System.out.print(df.format(this.month)
+ '/' + df.format(this.day) + '/'
+ df.format(this.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 = 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 + =
减小字号Ctrl + -
显示快捷键?