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

📄 datetochinese.java

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JAVA
字号:
// Fig. 3.02_02_01: DateToChinese.java
// 分离阿拉伯数字,并返回相应的中文大写日期

public class DateToChinese
{

  private String[] chineseNumber =
  {
    "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾"
  };

  public DateToChinese()
  {
    super();
  }

  public String getDayNumber(int day)
  {
    String output = "";
    if (day < 20)
    {
      output += getMonthNumber(day);
    }
    else if (day >= 20 && day < 30)
    {
      output += "贰拾";
      day -= 20;
      if (day == 0)
      {
        return "贰拾";
      }
      output += getCapitalNumber(day);
    }
    else
    {
      output += "叁拾";
      day -= 30;
      if (day == 0)
      {
        return "叁拾";
      }
      output += getCapitalNumber(day);
    }

    return output;
  }

  public String getMonthNumber(int month)
  {
    String output = "";
    if (month > 10)
    {
      output += "拾";
      month -= 10;
    }
    output += getCapitalNumber(month);
    return output;
  }

  // 分离阿拉伯数字,并返回相应的中文大写数字
  public String getCapitalNumber(int number)
  {
    int divisor = 1, digit;
    String output = "";

    //找到"最大的基数"
    for (int i = 1; i < number; i *= 10)
    {
      divisor = i;
    }

    while (divisor >= 1)
    {
      digit = quotient(number, divisor);

      output += chineseNumber[digit];

      number = remainder(number, divisor);
      divisor = quotient(divisor, 10);
    }

    return output;
  } //分离数字结束

  public int quotient(int a, int b)
  {
    return a / b;
  }

  public int remainder(int a, int b)
  {
    return a % b;
  }

} // end DateToChinese class

/**************************************************************************
 * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and               *
 * Prentice Hall. All Rights Reserved.                                    *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

⌨️ 快捷键说明

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