當前位置:編程學習大全網 - 編程軟體 - pm編程的快速編程技巧

pm編程的快速編程技巧

您好,根據您的要求,代碼如下。

導入Java . text . date format;

導入Java . text . parse exception;

導入Java . text . simple date format;

導入Java . util . date;

導入Java . util . scanner;

公共類測試{

公共靜態void main(String[] args) {

String[] day = new String[] {“天”、“壹”、“二”、“三”、“四”、“五”、“六”};

date format df = new simple date format(" yyyyMMdd ");//輸入的日期格式必須是這樣的。

Scanner s =新掃描儀(system . in);

while (true) {

System.out.println("以20120101的格式輸入日期");

嘗試{

date d = df . parse(s . nextline());//將字符串轉換為日期

system . out . println(" week "+day[d . getday()]);

} catch (ParseException e) {

System.out.println("非法輸入");

}

}

}

}

運行結果:

以20120101的格式輸入日期。

20111123

星期三

以20120101的格式輸入日期。

2011

非法輸入

以20120101的格式輸入日期。

  • 上一篇:Plc編程書籍推薦
  • 下一篇:如何從零開始做壹個 USB 鍵盤
  • copyright 2024編程學習大全網