當前位置:編程學習大全網 - 編程軟體 - 編程輸入輸出基礎知識參考

編程輸入輸出基礎知識參考

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

導入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的格式輸入日期。

  • 上一篇:蘋果手機鎖屏後無法回到鎖屏前的軟件?
  • 下一篇:maya軟件做動畫需不需要學代碼啊,如果需要的話,他是壹種什麽樣的代碼啊
  • copyright 2024編程學習大全網