candy898 2008-09-26 14:23
浏览 255
已采纳

JAVA问题

创建一个程序,它将MM/DD/YYYY格式 (例如4/23/2000) 这样的生日转换为3个单独的字符串。
class Birthday {
public static void main(String[] arguments) {
String birthday = "08/23/2002";
String month = birthday.substring(0, 2);
String day = birthday.substring(3, 5);
String year = birthday.substring(6, 10);
System.out.println("Birthday: " + birthday);
System.out.println("Month: " + month);
System.out.println("Day: " + day);
System.out.println("Year: " + year); }
}
为什么这个要这样写 birthday.substring(0, 2);
birthday.substring(3, 5);
birthday.substring(6, 10);

请具体解释一下 最好在具例说明! 非常谢谢!

  • 写回答

1条回答 默认 最新

  • lggegegmail 2008-09-26 14:38
    关注

    [code="java"] /**
    * Returns a new string that is a substring of this string. The
    * substring begins at the specified beginIndex and
    * extends to the character at index endIndex - 1.
    * Thus the length of the substring is endIndex-beginIndex.
    *


    * Examples:
    *


    * "hamburger".substring(4, 8) returns "urge"
    * "smiles".substring(1, 5) returns "mile"
    *

    *
    * @param beginIndex the beginning index, inclusive.
    * @param endIndex the ending index, exclusive.
    * @return the specified substring.
    * @exception IndexOutOfBoundsException if the
    * beginIndex is negative, or
    * endIndex is larger than the length of
    * this String object, or
    * beginIndex is larger than
    * endIndex.
    */
    public String substring(int beginIndex, int endIndex) {[/code]
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备