⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program9_1.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 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
  Date()   // this is a constructor method because it has the same
  {        // name as the class
    month = 7;
    day = 4;
    year = 2001;
  }
  public void setdate(int mm, int dd, int yyyy)
  {
    month = mm;
    day = dd;
    year = yyyy;
  }
  public void showdate()
  {
    DecimalFormat df = new DecimalFormat("00");
    
    System.out.println("The date is " + df.format(month)
              + '/' + df.format(day) + '/' 
              + df.format(year % 100)); // extract the last 2 year digits
  }
  public static void main(String[] args)
  {
    Date a = new Date();  // declare 2 objects of type Date
    Date b = new Date();    
    
    b.setdate(12,25,2002);  // assign values to b's data members 
    System.out.println( );
  
    a.showdate();  // display object a's values
    b.showdate();  // display object b's values
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -